小豬CMS已是當(dāng)前php軟件市場(chǎng)上的領(lǐng)跑者了,是一款開源的電商系統(tǒng),包含微信小程序、支付寶小程序、APP、公眾號(hào)和H5端,為大中小企業(yè)提供移動(dòng)電子商務(wù)優(yōu)秀的解決方案。今天我就來帶大家來做一次替換短信接口的工作。短信接口使用的是短信寶短信平臺(tái)的短信接口,小伙伴一定會(huì)問為什么使用短信寶作為案例呢?原因很簡(jiǎn)單,因?yàn)槎绦艑毜钠脚_(tái)極其穩(wěn)定,而且短信發(fā)送速度相當(dāng)快捷,驗(yàn)證碼和訂單通知在3~5秒就能收到,用戶體驗(yàn)非常好,所以我們公司一直和短信寶保持著合作關(guān)系,小伙伴們也可以去短信寶的官網(wǎng)(http://www.gjrencai.com)注冊(cè)一個(gè)賬號(hào),還有免費(fèi)的短信條數(shù)送呢。
打開項(xiàng)目 \cms\Lib\ORG\Sms.class.php 修改短信發(fā)送接口
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
public function sendSms($data = array(), $send_time = '' , $charset = 'utf-8' , $id_code = '' ) { if ($data) { $type = isset($data[ 'type' ]) ? $data[ 'type' ] : 'meal' ; $sendto = isset($data[ 'sendto' ]) ? $data[ 'sendto' ] : 'user' ; $mer_id = isset($data[ 'mer_id' ]) ? intval($data[ 'mer_id' ]) : 0; $store_id = isset($data[ 'store_id' ]) ? intval($data[ 'store_id' ]) : 0; $uid = isset($data[ 'uid' ]) ? intval($data[ 'uid' ]) : 0; if (empty($mer_id)) return 'mer_id is null' ; $content = isset($data[ 'content' ]) ? Sms::_safe_replace($data[ 'content' ]) : '' ; if (empty($content)) return 'send content is null' ; $mobile = isset($data[ 'mobile' ]) ? $data[ 'mobile' ] : '' ; $phone_array = explode( ',' , $mobile); $mobile = $pre = '' ; foreach ($phone_array as $phone) { if (Sms::checkmobile($phone)) { $mobile .= $pre . $phone; $pre = ',' ; } } if (empty($mobile)) return 'phone is right' ; $data = array( //'topdomain' => C('config.sms_server_topdomain'), 'u' => trim(C( 'config.sms_name' )), 'p' => md5(trim(C( 'config.sms_key' ))), //'token' => $mer_id . 'o2opigcms', 'm' => $mobile, 'c' => "【" .trim(C( 'config.sms_sign' )). "】" .$content ); $post = '' ; foreach ($data as $k => $v) { $post .= $k . '=' . $v . '&' ; } $ return = file_get_contents($smsapi_senturl.http_build_query($data)); $statusStr = array( "0" => "短信發(fā)送成功" , "-1" => "參數(shù)不全" , "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!" , "30" => "密碼錯(cuò)誤" , "40" => "賬號(hào)不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內(nèi)容含有敏感詞" ); //$arr = explode('#', $return); $send_time = $send_time ? $send_time : time(); //增加到本地?cái)?shù)據(jù)庫 $row = array( 'mer_id' => $mer_id, 'uid' => $uid, 'store_id' => $store_id, 'time' => $send_time, 'phone' => $mobile, 'text' => $content, 'status' => $arr[0], 'type' => $type, 'sendto' => $sendto); D( 'Sms_record' )->add($row); return $statusStr[$ return ]; } else return false ; exit; if (C( 'sms_key' ) != '' && C( 'sms_key' ) != 'key' ) { $companyid=0; if (!(strpos($token, '_' ) === FALSE)) { $sarr = explode( '_' ,$token); $token = $sarr[0]; $companyid = intval($sarr[1]); } if (!$mobile) { $companyWhere = array(); $companyWhere[ 'token' ] = $token; if ($companyid) { $companyWhere[ 'id' ] = $companyid; } $company = M( 'Company' )->where($companyWhere)->find(); $mobile = $company[ 'mp' ]; } // $thisWxUser = M( 'Wxuser' )->where(array( 'token' => Sms::_safe_replace($token)))->find(); $thisUser = M( 'Users' )->where(array( 'id' => $thisWxUser[ 'uid' ]))->find(); if ($token == 'admin' ) { $thisUser = array( 'id' =>0); $thisWxUser = array( 'uid' => 0, 'token' => $ this ->token); } $get_url= "http://api.smsbao.com/query?u=" .trim(C( 'config.sms_name' )). "&p=" .md5(trim(C( 'config.sms_key' ))); $num_smsbao=file_get_contents($get_url); $num_smsbao=str_replace( "\n" , "" , $num_smsbao); $num_smsbao_res=explode( "," ,$num_smsbao); //$num_smsbao_res[1] if ($num_smsbao_res[1] < 1 || $num_smsbao==30||$num_smsbao==40||$num_smsbao==41||$num_smsbao==42){ return '已用完或者未購買短信包' ; exit(); } else { // //短信發(fā)送狀態(tài) if (is_array($mobile)){ $mobile = implode( "," , $mobile); } $content = Sms::_safe_replace($content); $data = array( //'topdomain' => C('config.sms_server_topdomain'), 'u' => trim(C( 'config.sms_name' )), 'p' => md5(trim(C( 'config.sms_key' ))), //'token' => $mer_id . 'o2opigcms', 'm' => $mobile, 'c' => "【" .trim(C( 'config.sms_sign' )). "】" .$content ); $post = '' ; foreach ($data as $k => $v) { $post .= $k . '=' . $v . '&' ; } $ return = file_get_contents($smsapi_senturl.http_build_query($data)); //Sms::_post($smsapi_senturl, 0, $post); $statusStr = array( "0" => "短信發(fā)送成功" , "-1" => "參數(shù)不全" , "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!" , "30" => "密碼錯(cuò)誤" , "40" => "賬號(hào)不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內(nèi)容含有敏感詞" ); //$arr = explode('#', $return); //$this->statuscode = $arr[0]; //增加到本地?cái)?shù)據(jù)庫 if ($mobile) { $row = array( 'uid' => $thisUser[ 'id' ], 'token' => $thisWxUser[ 'token' ], 'time' => time(), 'mp' => $mobile, 'text' => $content, 'status' => $ this ->statuscode, 'price' => C( 'sms_price' )); M( 'Sms_record' )->add($row); if (intval($ this ->statuscode) == 0 && $token != 'admin' ){ M( 'Users' )->where(array( 'id' => $thisWxUser[ 'uid' ]))->setDec( 'smscount' ); } } //end return $statusStr[$ return ]; } } } |
打開項(xiàng)目:\cms\Lib\Action\Index 新建一個(gè)smsbaoAction.class.php文件
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?php /* *短信寶插件 * */ class smsbaoAction extends BaseAction { public function index(){ $row = array( 'name' => 'sms_name' , 'type' => 'type=text&validate=required:true' , 'value' => 'smsbao' , 'info' => '短信寶用戶名' , 'desc' => '你在短信寶注冊(cè)的用戶名' , 'tab_id' => '0' , 'tab_name' => '' , 'gid' => '15' , 'sort' => '12' , 'status' => '1' ); $add=M( 'config' )->add($row); echo "<h4>小豬o2o短信寶短信插件安裝成功,請(qǐng)刪除install_smsbao.php文件</h4>" ; } } |
經(jīng)過上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的小豬oto生活通V14.17系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類