diff --git a/app/controllers/ControllerBase.php b/app/controllers/ControllerBase.php index 5de87dc..f3c8147 100644 --- a/app/controllers/ControllerBase.php +++ b/app/controllers/ControllerBase.php @@ -80,7 +80,52 @@ class ControllerBase extends Phalcon\Mvc\Controller{ curl_close($curl); return $res; } - + + /** + * curl post + * 因为旧的发送短信地址对于内容有限制,get方式最多1000的字符,长了发布出去,所以需要改成新接口解决这个问题 + */ + function __http_post_new($url, $param, $hearder=null) + { + $oCurl = curl_init(); + if (stripos($url, "https://") !== FALSE) { + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false); + } + if (is_string($param)) { + $strPOST = $param; + } else if (is_array($param)) { + $strPOST = json_encode($param); + } else { + exit(); + } + + curl_setopt($oCurl, CURLOPT_URL, $url); + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($oCurl, CURLOPT_POST, true); + curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST); + curl_setopt($oCurl, CURLOPT_TIMEOUT, 50); // 超时 + if (! empty($hearder)) { + curl_setopt($oCurl, CURLOPT_HTTPHEADER, array( + 'Accept: application/json', + 'Content-Type: application/json; charset=utf-8', + 'Content-Length: ' . strlen($strPOST), + 'Authorization: ' . $hearder + )); + } else { + curl_setopt($oCurl, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json; charset=utf-8', + 'Content-Length: ' . strlen($strPOST) + )); + } + + $sContent = curl_exec($oCurl); + $aStatus = curl_getinfo($oCurl); + curl_close($oCurl); + return $sContent; + } + + /** * 跳转页面方法封装,针对后台跳转使用 */ @@ -308,5 +353,30 @@ class ControllerBase extends Phalcon\Mvc\Controller{ return $rs; } + /** + * 新短信发送接口 + */ + function __send_sms($request_arr=array()){ + $result = []; + $url = 'https://yunapi.wemediacn.com/smsapi/v2/SendSMS'; + $infoArr = []; + $infoArr['mobile'] = (string)$request_arr['mobile']; + $infoArr['message'] = (string)$request_arr['content']; + $infoArr['format'] = 1; + $infoArr['extNumber'] = ""; + $infoArr['appid'] = (string)$request_arr['appid']; + $infoArr['secret'] = (string)$request_arr['secret']; + $returnObj = json_decode($this->__http_post_new($url, $infoArr),true); + if($returnObj['ret'] == 0 && $returnObj['info'] == 'OK'){ + $result['errcode'] = 0; + $result['errmsg'] = 'OK'; + $result['message_id'] = $returnObj['msgid']; + }else{ + $result['errcode'] = $returnObj['ret']; + $result['errmsg'] = $returnObj['info']; + $result['message_id'] = $returnObj['ret'].$returnObj['info']; + } + return $result; + } } ?> \ No newline at end of file diff --git a/app/controllers/SmsController.php b/app/controllers/SmsController.php index 7cf4aa0..cbd1afc 100644 --- a/app/controllers/SmsController.php +++ b/app/controllers/SmsController.php @@ -153,7 +153,7 @@ class SmsController extends ControllerBase{ $rs['errcode'] = 50000; $rs['data'] = null; - $this->_LogObj->LogWrite(TIFFANY_API_CHECK_LOG, 'send===xml:'.json_encode($xml).'===='.$url); + // $this->_LogObj->LogWrite(TIFFANY_API_CHECK_LOG, 'send===xml:'.json_encode($xml).'===='.$url); } //如果发送成功 diff --git a/app/controllers/TestController.php b/app/controllers/TestController.php new file mode 100644 index 0000000..c8a568a --- /dev/null +++ b/app/controllers/TestController.php @@ -0,0 +1,29 @@ +__send_sms($request_send); + print_r($request_data);die; + } +} +?> \ No newline at end of file