5

中国移动MAS平台短信发送PHP代码

 1 year ago
source link: https://www.iplayio.cn/post/469404583
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

中国移动MAS平台短信发送PHP代码

发布:21小时前 更新:21小时前 folder_open 计算机编程语言 PHP编程 12 浏览 comment

原文地址:中国移动MAS平台短信发送PHP代码

中国移动MAS平台短信发送PHP代码

业务功能
HTTP客户端向云MAS平台发送短信任务请求,云MAS平台接收到请求后验证数据,验证通过将数据发送给短信网关。

1、请求
名称 类型 说明
ecName String 企业名称。
apId String 接口账号用户名。
mobiles String 收信手机号码。英文逗号分隔,每批次限5000个号码,例:“13800138000,13800138001,13800138002”。
content String 短信内容。
sign String 签名编码。在云MAS平台『EC管理』→『接口管理』→『短信接入用户管理』获取。
addSerial String 扩展码。依据申请开户的服务代码匹配类型而定,如为精确匹配,此项填写空字符串(””);如为模糊匹配,此项可填写空字符串或自定义的扩展码,注:服务代码加扩展码总长度不能超过20位。
mac String 参数校验序列,生成方法:将ecName、apId、secretKey、mobiles、content、sign、addSerial按序拼接(无间隔符),通过MD5(32位小写)计算得出值。

2、响应
名称 类型 说明
rspcod String 响应状态,详见下表。
mgsGroup String 消息批次号,由云MAS平台生成,用于关联短信发送请求与状态报告,注:若数据验证不通过,该参数值为空。
success boolean 数据校验结果。

3、rspcod 说明
IllegalMac mac校验不通过。
IllegalSignId 无效的签名编码。
InvalidMessage 非法消息,请求数据解析失败。
InvalidUsrOrPwd 非法用户名/密码。
NoSignId 未匹配到对应的签名信息。
success 数据验证通过。
TooManyMobiles 手机号数量超限(>5000),应≤5000。

$url = 'http://112.35.1.155:1992/sms/norsubmit'; // 短信平台URL
        $content = '您的验证码是:'.$pin.',请勿向任何人泄露。【'.Config::get('site.name').'】'; // 短信内容
        $mac = Config::get('site.ecname').Config::get('site.ydsms_username').Config::get('site.ydsms_password').$phone.$content
        .Config::get('site.ydsms_sign')." ";
        $mac = md5($mac);
        $data = [
            'ecName' => Config::get('site.ecname'),
            'apId' => Config::get('site.ydsms_username'),
            'secretKey' => Config::get('site.ydsms_password'),
            'mobiles' => $phone,
            'content' => $content,
            'sign' => Config::get('site.ydsms_sign'),
            'addSerial' => ' ',
            'mac' => $mac
        ];
        $json = json_encode($data);
        $data = base64_encode($json);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 执行之后不直接打印出来
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        $res = curl_exec($curl);
        adlog("发送短信请求结果",[$res,$json]);
        return json_decode($res,true)['success'] ?? false;

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK