短信发送接口升级v2新接口版本
This commit is contained in:
parent
f63a901141
commit
ecbce91a70
@ -81,6 +81,51 @@ class ControllerBase extends Phalcon\Mvc\Controller{
|
|||||||
return $res;
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@ -153,7 +153,7 @@ class SmsController extends ControllerBase{
|
|||||||
$rs['errcode'] = 50000;
|
$rs['errcode'] = 50000;
|
||||||
$rs['data'] = null;
|
$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);
|
||||||
|
|
||||||
}
|
}
|
||||||
//如果发送成功
|
//如果发送成功
|
||||||
|
|||||||
29
app/controllers/TestController.php
Normal file
29
app/controllers/TestController.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 方法测试
|
||||||
|
* @author WMQ
|
||||||
|
*/
|
||||||
|
header("Content-Type:text/html; Charset=utf-8");
|
||||||
|
|
||||||
|
class TestController extends ControllerBase{
|
||||||
|
|
||||||
|
function initialize(){
|
||||||
|
parent::initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试方法
|
||||||
|
* http://127.0.0.1/tiffany/api/test/info
|
||||||
|
* http://weapp.wemediacn.net/d/tiffany/api/test/info
|
||||||
|
*/
|
||||||
|
function infoAction(){
|
||||||
|
$request_send = [];
|
||||||
|
$request_send['mobile'] = '18221936436';
|
||||||
|
$request_send['content'] = '尊敬的 韩 Mrs.,您的订单 601369630已发货。物流单号: 923080391113。线上订单均享专属密令签收服务。 请务必在查验作品无误后,再将签收码告知派送人员。 您在蒂芙尼线上旗舰店选购的珠宝作品,除部分款式(不便附着)外都将附随品牌商品芯片标签,不影响您检查或试戴作品。请您确定毋须无理由退货后,再拆除该标签,详情可见店内具体条款。项链、手链或戒指作品,如需长短或尺码调整,欢迎联系蒂芙尼在线顾问获取专属定制建议,亦可致电4008201837在线办理急速换货。如需协助,欢迎致电蒂芙尼客户关怀中心:4008201837。';
|
||||||
|
$request_send['appid'] = '71006100';
|
||||||
|
$request_send['secret'] = '5391b239e8c494e4303dc54c24012ab77cce6c88';
|
||||||
|
$request_data = $this->__send_sms($request_send);
|
||||||
|
print_r($request_data);die;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user