<?php
header("Content-type:text/html; charset=UTF-8");
//请检查环境是否 开启 curl init。
function Post($curlPost,$url){
$curlPost = json_encode($curlPost, JSON_UNESCAPED_UNICODE); //将数组转换为JSON格式
$headers = array(
'Content-Type: application/json; charset=utf-8', //设置请求头
'Content-Length: ' . strlen($curlPost) //设置请求体长度
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); //设置请求头
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$return_str = curl_exec($curl);
curl_close($curl);
return $return_str;
}
//短信接口地址
$target = "https://api.ihuyi.com/mms/v1/batchSend";
$api_key = 'xxxxxxxxxxxxxx'; //请替换为您的APIKEY
$post_data = array(
'api_id' => 'mms-xxxxxxxx', //APIID(用户中心【富媒体短信】-【5G视频短信】-【产品总览】查看)
'signature' => 'xxxxxxxxx', //请求验证加密签名(非彩信签名);
签名生成方式:
仅公共参数以ASCII码从小到大排序值,key=value,多值以“&”隔开,拼接之后md5 32位小写; 如:md5(api_id=xxxx&api_key=xxxx&request_id=xxxxxxxx×tamp=xxxxxxx)
APIKEY(用户中心【富媒体短信】-【5G视频短信】-【产品总览】查看)
2、动态密码(生成动态密码方式请看该文档末尾的说明)
'timestamp' => 1623643787, //东八时区;10位时间戳,时间允许相差±60S
'request_id' => 'xxxxxxxxxxxx', //请求方请求ID,建议使用唯一ID,比如使用uuid;我方系统会2小时内去重验证处理,防止网络重复攻击;
'product_id' => 1001, //产品ID
'phone' => array(0=>'18800000000',1=>'18800000001'), //手机号数组(最多1万个号码)
'sign_name' => 'xxxxxxxx', //彩信签名(template_id未填写则必填)
'title' => 'xxxxxxxxxxxx', //彩信标题(template_id未填写则必填)
'content' => array(0=>array('con_type'=>'txt','ext_type'=>'','data'=>'将原始内容base64编码'),1=>array('con_type'=>'img','ext_type'=>'jpg','data'=>'将原始内容base64编码')), //彩信内容和模板ID必须传入1个;当彩信内容和模板ID都传入时,传入内容生效,模板ID属性失效 彩信元素DataItem结构:(具体参照文档9.01)
'template_id' => 1, //模板ID(内容为空则必填)
'send_time' => '2020-08-26 16:08:14', //定时发送时间
);
$post_data['timestamp'] = time();
$post_data['request_id'] = $post_data['timestamp'].rand(0,9999);
$signature = 'api_id=' . $post_data['api_id'] . '&' . 'api_key=' . $api_key . '&' . 'request_id=' . $post_data['request_id'] . '&' . 'timestamp=' . $post_data['timestamp'];
$post_data['signature'] = md5($signature);
$res = Post($post_data, $target);
print_r($res);
在线咨询
150,000家
企业客户
21年
行业经验
2V1
2对1客户支持