[英]How to switch from twilio to another sms gateway like fast2sms
我正在使用 Twilio 在我的 Codeigniter Angular 电子商务应用程序中发送短信。 现在我想从 twilio 切换到另一个短信网关 fast2sms。 这是我的代码...
public function twilloMessage(){
$agent = $this->input->request_headers();
$saveLogInfo = array(
'url' => $this->uri->uri_string(),
'agent' => json_encode($agent),
'datetime' => date('Y-m-d h:i:s')
);
$this->Users_model->saveUserLogs($saveLogInfo);
$auth = $this->input->get_request_header('Basic');
if($auth && $auth == $this->config->item('encryption_key')){
$required = ['to','msg'];
$data = $this->check_array_values($_POST,$required);
$param = $this->check_params($_POST,$required);
if(isset($data) && !empty($data)){
echo $this->json->response($data,$this->_Errmessage,$this->_statusErr);
}else if(count($param) >0 ){
echo $this->json->response(array_values($param),$this->_ParamMessage,$this->_statusErr);
}else{
$settings = $this->Settings_model->get_all();
if($settings != null){
$cred = json_decode($settings[0]->creds);
// echo $this->json->response($cred,$this->_OKmessage,$this->_statusOK);
$id = $cred->sid;
$token = $cred->token;
$url = "https://api.twilio.com/2010-04-01/Accounts/$id/SMS/Messages";
$from = $cred->from;
$to = $_POST['to']; // twilio trial verified number
$otp = $this->Users_model->random_number();
$body = $_POST['msg'].' '.$otp;
$data = array (
'From' => $from,
'To' => $to,
'Body' => $body,
);
$post = http_build_query($data);
$x = curl_init($url );
curl_setopt($x, CURLOPT_POST, true);
curl_setopt($x, CURLOPT_RETURNTRANSFER, true);
curl_setopt($x, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($x, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($x, CURLOPT_USERPWD, "$id:$token");
curl_setopt($x, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($x);
curl_close($x);
$dataResponse = $this->Users_model->saveVerifyCode($otp,$_POST['to']);
if($dataResponse != null){
$dataResponse['code'] = null;
echo $this->json->response($dataResponse,$this->_OKmessage,$this->_statusOK); // live
// echo $this->json->response(['otp'=>$dataResponse,'twillo'=>$response],$this->_OKmessage,$this->_statusOK); // productions
}else{
echo $this->json->response(['message'=>'Something went wrong1'],$this->_Errmessage,$this->_statusErr);
}
}else{
echo $this->json->response(['message'=>'Something went wrong2'],$this->_Errmessage,$this->_statusErr);
}
}
}else{
echo $this->json->response('No Token Found',$this->_Errmessage,$this->_statusErr);
}
}
这是发送短信的fast2sms代码...
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.fast2sms.com/dev/bulkV2?authorization=YOUR_API_KEY&sender_id=DLT_APPROVED_SENDER_ID&message=".urlencode('DLT_APPROVED_MESSAGE')."&template_id=DLT_CONTENT_TEMPLATE_ID&entity_id=DLT_ENTITY_ID&route=dlt_manual&numbers=".urlencode('9999999999,8888888888,7777777777'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
我正在使用 Twilio 在我的 Codeigniter Angular 电子商务应用程序中发送短信。 现在我想从 twilio 切换到另一个短信网关 fast2sms。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.