likeshop是一款開源的企業級B2C電商系統,前端uni-app架構,極致節省開發成本,一次研發,多端發布。后端ThinkPHP架構,國內最流行的PHP研發框架,易用易學,好二開。小編帶著大家一起開發likeshop商城3.0.3.20231204的短信寶插件接口。我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
首先執行以下sql
|
1
|
INSERT INTO `ls_sms_config` ( `name`, `describe`, `sign`, `app_key`, `secret_key`, `status`, `del`) VALUES ('短信寶', '短信寶短信服務', '', '', '', '0', '0'); |
接著我們打開項目application\common\behavior\SmsSend.php文件,在97行~112行增加以下代碼:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
}elseif ($this->channel == 3) { // 短信寶 $res = (new Smsbao($this->config)) ->setMobile($this->mobile) ->setContent($this->content) ->sendSms(); if (isset($res['Code']) && $res['Code'] == 'Ok') { $send_status = SmsLog::send_success; $this->updateSmsLog($send_status, $res); return true; } else { $send_status = SmsLog::send_fail; $this->updateSmsLog($send_status, $res); $message = $res['Message'] ?? json_encode($res); throw new Exception('短信配置錯誤:' . $message); } } |
接著打開項目application\common\server 目錄,新增 Smsbao.php 文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<?phpnamespace app\common\server;use think\Exception;class Smsbao{ private $app_key = ''; private $secret_key = ''; private $sign = ''; private $mobile = ''; private $content= ''; public function __construct($config) { $this->sign = $config['sign']; $this->app_key = $config['app_key']; $this->secret_key = $config['secret_key']; } public function setContent($template_code){ $this->content = $template_code; return $this; } public function setMobile($mobile){ $this->mobile = $mobile; return $this; } public function sendSms(){ try { $statusStr = array( "0" => "短信發送成功", "-1" => "參數不全", "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!", "30" => "密碼錯誤", "40" => "賬號不存在", "41" => "余額不足", "42" => "帳戶已過期", "43" => "IP地址限制", "50" => "內容含有敏感詞" ); $user = $this->app_key; //短信平臺帳號 $pass = md5($this->secret_key); //短信平臺密碼 $sign = '【'.$this->sign.'】'; //短信平臺密碼 $content=$sign.$this->content;//要發送的短信內容 $phone = $this->mobile;//要發送短信的手機號碼 $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content); $result = $this->curl_get($sendurl); $res = []; if ($result == 0){ $res['Code'] ='OK'; }else{ $res['Code'] ='fail'; $res['Message'] =$statusStr[$result]; } return $res; // return $result->toArray(); } catch(Exception $e){ return $e->getMessage() . PHP_EOL; } } private function curl_get($sendurl){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $sendurl); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不驗證證書// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不驗證證書 $result = curl_exec($ch); curl_close($ch); return $result; }} |
好了經過以上的添加,短信寶的短信平臺已經替換成功了,可以正常使用了

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的likeshop系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類