聚合短信接口-- php


 1 $sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL
 2 $smsConf = array(
 3   'key' => $juhekey,                   //您申請的APPKEY
 4   'mobile' => $tel,                    //接受短信的用戶手機號碼
 5   'tpl_id' => $juheid,                 //您申請的短信模板ID,根據實際情況修改
 6   'tpl_value' => '#code#=' . $smscode, //您設置的模板變量隨機數,根據實際情況修改
 7 );
 8 
 9 $content = juhecurl($sendUrl, $smsConf, 1); //請求發送短信
10 if ($content) {
11   $result = json_decode($content, true);
12   $error_code = $result['error_code'];
13   if ($error_code == 0) {
14     $return = array('status' => 1, 'msg' => '短信發送成功');
15   } else {
16     //狀態非0,說明失敗
17     $return['msg'] = $result['reason'];
18   }
19 } else {
20 //返回內容異常,以下可根據業務邏輯自行修改
21   $return['msg'] = "請求發送短信失敗";
22 }
23 
26 //函數相當於file_get_contents
28 function juhecurl($url, $params = false, $ispost = 0){
29 $httpInfo = array();
30 $ch = curl_init();
31 curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
32 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22');
33 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
34 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
35 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
36 if ($ispost) {
37 curl_setopt($ch, CURLOPT_POST, true);
38 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
39 curl_setopt($ch, CURLOPT_URL, $url);
40 } else {
41 if ($params) {
42 curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
43 } else {
44 curl_setopt($ch, CURLOPT_URL, $url);
45 }
46 }
47 $response = curl_exec($ch);
48 if ($response === FALSE) {
49 //echo "cURL Error: " . curl_error($ch);
50 return false;
51 }
52 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
53 $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
54 curl_close($ch);
55 return $response;
56 }

 

具體接口 get/post參數獲取返回結果還可以參考:https://www.cnblogs.com/CHEUNGKAMING/p/5717429.html 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM