InternationalSMSMultiXsendDemo
代码示列
<?php
$version = "1";
$sign_type = "md5";
$appid = "your_appid";
$appkey = "your_appkey";
$product = "internationalsms";
$project = "RPfdH2";
$multi = array();
$to_address_array = array('15201893074','152xxxxxxxx');
foreach ($to_address_array as $value) {
$temp['to'] = $value;
$temp['array'] = array("name"=>"Dduan");
array_push($multi, $temp);
}
$url = 'http://api.mysubmail.com/'.$product.'/multixsend.json';
if($sign_type != "md5" && $sign_type != "sha1"){
$post_data = array(
"appid" => $appid,
"signature"=>$appkey,
"project"=>$project,
"multi"=>json_encode($multi),
);
}else{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.mysubmail.com/service/timestamp.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
$timestamp = $output['timestamp'];
$post_data = array(
"appid" => $appid,
"project"=>$project,
"timestamp"=>$timestamp,
"sign_type"=>$sign_type,
"sign_version"=>$version,
"multi"=>json_encode($multi),
);
$temp = $post_data;
if($version == '2'){
unset($temp['multi']);
}else{
unset($temp['sign_version']);
}
ksort($temp);
reset($temp);
$tempStr = "";
foreach ($temp as $key => $value) {
$tempStr.=$key."=".$value."&";
}
$tempStr = substr($tempStr,0,count($tempStr)-2);
if($sign_type == "md5")
$post_data['signature'] = md5($appid.$appkey.$tempStr.$appid.$appkey);
else
$post_data['signature'] = sha1($appid.$appkey.$tempStr.$appid.$appkey);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
echo json_encode($output);