<?php
header("Content-type:text/html; charset=UTF-8");
//請檢查環(huán)境是否 開啟 curl init。
function Post($curlPost,$url){
$curlPost = json_encode($curlPost, JSON_UNESCAPED_UNICODE); //將數(shù)組轉換為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'; //請?zhí)鎿Q為您的APIKEY
$post_data = array(
'api_id' => 'mms-xxxxxxxx', //APIID(用戶中心【富媒體短信】-【5G視頻短信】-【產品總覽】查看)
'signature' => 'xxxxxxxxx', //請求驗證加密簽名(非彩信簽名);
簽名生成方式:
僅公共參數(shù)以ASCII碼從小到大排序值,key=value,多值以“&”隔開,拼接之后md5 32位小寫; 如:md5(api_id=xxxx&api_key=xxxx&request_id=xxxxxxxx×tamp=xxxxxxx)
APIKEY(用戶中心【富媒體短信】-【5G視頻短信】-【產品總覽】查看)
2、動態(tài)密碼(生成動態(tài)密碼方式請看該文檔末尾的說明)
'timestamp' => 1623643787, //東八時區(qū);10位時間戳,時間允許相差±60S
'request_id' => 'xxxxxxxxxxxx', //請求方請求ID,建議使用唯一ID,比如使用uuid;我方系統(tǒng)會2小時內去重驗證處理,防止網絡重復攻擊;
'product_id' => 1001, //產品ID
'phone' => array(0=>'18800000000',1=>'18800000001'), //手機號數(shù)組(最多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', //定時發(fā)送時間
);
$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);
國內專業(yè)互聯(lián)網團隊
21年行業(yè)經驗
7x24小時售后支持
豐富的行業(yè)經驗
Copyright ? 2004-2025 上海思銳信息技術有限公司 All rights reserved. 滬ICP備07035915號-15 電信增值業(yè)務許可證:B2-20160082
服務熱線:
4008 808 898
服務熱線(工作時間):
4008 808 898
業(yè)務咨詢(非工作時間):
售后咨詢(非工作時間):
驗證碼已發(fā)送到您的手機,請查收!
輸入驗證碼后,點擊“開通體驗賬戶”按鈕可立即開通體驗賬戶。