阿里大鱼 阿里云api

 阿里短信服务API接入指南及示例  : https://yq.aliyun.com/articles/59928

 

=========================================================================================================

<?php $app_key = "*********"; $app_secret = "*******************************"; $request_paras = array( 'ParamString' => '{"name":"XXXX"}', 'RecNum' => '18600000000,13500000000', 'SignName' =>'签名名称', 'TemplateCode' => '模板CODE' ); $request_host = "http://sms.market.alicloudapi.com"; $request_uri = "/singleSendSms"; $request_method = "GET"; $info = ""; $content = do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, $info); print_r($content); // API返回值# print_r($info); // 系统请求返回信息function do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, &$info) { ksort($request_paras); $request_header_accept = "application/json;charset=utf-8"; $content_type = ""; $headers = array( 'X-Ca-Key' => $app_key, 'Accept' => $request_header_accept ); ksort($headers); $header_str = ""; $header_ignore_list = array('X-CA-SIGNATURE', 'X-CA-SIGNATURE-HEADERS', 'ACCEPT', 'CONTENT-MD5', 'CONTENT-TYPE', 'DATE'); $sig_header = array(); foreach($headers as $k => $v) { if(in_array(strtoupper($k), $header_ignore_list)) { continue; } $header_str .= $k . ':' . $v . " "; array_push($sig_header, $k); } $url_str = $request_uri; $para_array = array(); foreach($request_paras as $k => $v) { array_push($para_array, $k .'='. $v); } if(!empty($para_array)) { $url_str .= '?' . join('&', $para_array); } $content_md5 = ""; $date = ""; $sign_str = ""; $sign_str .= $request_method ." "; $sign_str .= $request_header_accept." "; $sign_str .= $content_md5." "; $sign_str .= " "; $sign_str .= $date." "; $sign_str .= $header_str; $sign_str .= $url_str; $sign = base64_encode(hash_hmac('sha256', $sign_str, $app_secret, true)); $headers['X-Ca-Signature'] = $sign; $headers['X-Ca-Signature-Headers'] = join(',', $sig_header); $request_header = array(); foreach($headers as $k => $v) { array_push($request_header, $k .': ' . $v); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_host . $url_str); //curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $ret = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); return $ret; }

<?php $app_key = "*********"; $app_secret = "*******************************"; $request_paras = array( 'ParamString' => '{"name":"XXXX"}', 'RecNum' => '18600000000,13500000000', 'SignName' =>'签名名称', 'TemplateCode' => '模板CODE' ); $request_host = "http://sms.market.alicloudapi.com"; $request_uri = "/singleSendSms"; $request_method = "GET"; $info = ""; $content = do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, $info); print_r($content); // API返回值# print_r($info); // 系统请求返回信息function do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, &$info) { ksort($request_paras); $request_header_accept = "application/json;charset=utf-8"; $content_type = ""; $headers = array( 'X-Ca-Key' => $app_key, 'Accept' => $request_header_accept ); ksort($headers); $header_str = ""; $header_ignore_list = array('X-CA-SIGNATURE', 'X-CA-SIGNATURE-HEADERS', 'ACCEPT', 'CONTENT-MD5', 'CONTENT-TYPE', 'DATE'); $sig_header = array(); foreach($headers as $k => $v) { if(in_array(strtoupper($k), $header_ignore_list)) { continue; } $header_str .= $k . ':' . $v . " "; array_push($sig_header, $k); } $url_str = $request_uri; $para_array = array(); foreach($request_paras as $k => $v) { array_push($para_array, $k .'='. $v); } if(!empty($para_array)) { $url_str .= '?' . join('&', $para_array); } $content_md5 = ""; $date = ""; $sign_str = ""; $sign_str .= $request_method ." "; $sign_str .= $request_header_accept." "; $sign_str .= $content_md5." "; $sign_str .= " "; $sign_str .= $date." "; $sign_str .= $header_str; $sign_str .= $url_str; $sign = base64_encode(hash_hmac('sha256', $sign_str, $app_secret, true)); $headers['X-Ca-Signature'] = $sign; $headers['X-Ca-Signature-Headers'] = join(',', $sig_header); $request_header = array(); foreach($headers as $k => $v) { array_push($request_header, $k .': ' . $v); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_host . $url_str); //curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $ret = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); return $ret; }

123

<?php
$app_key = "DLTAIC5J9oxhB6mN0F";
$app_secret = "DD7CVlBBMqh1SOHDiSIslXUNGUUzyHL";
$request_paras = array(
'ParamString' => '{"name":"123456"}',
'RecNum' => '15076263366',
'SignName' =>'阿里云短信测试专用',
'TemplateCode' => 'SMS_102400010'
);

$request_host = "http://sms.market.alicloudapi.com";
$request_uri = "/singleSendSms";
$request_method = "GET";
$info = "";
$content = do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, $info);
print_r($content); // API返回值
# print_r($info); // 系统请求返回信息

function do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, &$info) {
ksort($request_paras);
$request_header_accept = "application/json;charset=utf-8";
$content_type = "";
$headers = array(
'X-Ca-Key' => $app_key,
'Accept' => $request_header_accept
);
ksort($headers);
$header_str = "";
$header_ignore_list = array('X-CA-SIGNATURE', 'X-CA-SIGNATURE-HEADERS', 'ACCEPT', 'CONTENT-MD5', 'CONTENT-TYPE', 'DATE');
$sig_header = array();
foreach($headers as $k => $v) {
if(in_array(strtoupper($k), $header_ignore_list)) {
continue;
}
$header_str .= $k . ':' . $v . " ";
array_push($sig_header, $k);
}
$url_str = $request_uri;
$para_array = array();
foreach($request_paras as $k => $v) {
array_push($para_array, $k .'='. $v);
}
if(!empty($para_array)) {
$url_str .= '?' . join('&', $para_array);
}
$content_md5 = "";
$date = "";
$sign_str = "";
$sign_str .= $request_method ." ";
$sign_str .= $request_header_accept." ";
$sign_str .= $content_md5." ";
$sign_str .= " ";
$sign_str .= $date." ";
$sign_str .= $header_str;
$sign_str .= $url_str;

$sign = base64_encode(hash_hmac('sha256', $sign_str, $app_secret, true));
$headers['X-Ca-Signature'] = $sign;
$headers['X-Ca-Signature-Headers'] = join(',', $sig_header);
$request_header = array();
foreach($headers as $k => $v) {
array_push($request_header, $k .': ' . $v);
}

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $request_host . $url_str);
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return $ret;
}

 

原文地址:https://www.cnblogs.com/vip-deng-vip/p/7723495.html