最近小編知道云EC商城更新了,之前的短信接口插件也不能用。今天小編為大家講解一下云EC商城1.2.1版本的短信接口開發(fā),我們使用的短信接口是我們短信寶短信群發(fā)平臺的接口,我們短信寶短信平臺非常穩(wěn)定,發(fā)送速度快,注冊就送測試短信,推薦大家使用。
首先我們新建\inc\plugin\sms\smsbao\文件夾,創(chuàng)建文件名為: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
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
|
<?php if (!defined( 'in_mx' )) { exit ( 'Access Denied' );} date_default_timezone_set( 'Asia/Shanghai' ); $sms_mod = array (); $sms_mod [ 'code' ] = "smsbao" ; //代碼 $sms_mod [ 'name' ] = '短信寶' ; //名稱 $sms_mod [ 'config' ] = json_encode( array ( 'appkey' => '' , 'secretKey' => '' , 'reg' => '' , 'login' => '' , 'updatepwd' => '' , 'setpaypwd' => '' , 'changemobile' => '' )); //配置信息 $sms_param = array ( array ( 'name' => 'smsconfig_appkey' , 'value' => 'appkey' , 'type' => 'text' , 'desc' => "短信寶用戶名,還沒有短信寶賬戶?點擊馬上<a href='http://www.gjrencai.com' target='_blank'>免費注冊</a>" ), array ( 'name' => 'smsconfig_secretKey' , 'value' => 'secretKey' , 'type' => 'text' , 'desc' => '短信寶密碼' ), array ( 'name' => 'smsconfig_reg' , 'value' => '注冊模板' , 'type' => 'text' , 'desc' => '' ), array ( 'name' => 'smsconfig_login' , 'value' => '登錄模板' , 'type' => 'text' , 'desc' => '' ), array ( 'name' => 'smsconfig_updatepwd' , 'value' => '修改密碼模板' , 'type' => 'text' , 'desc' => '' ), array ( 'name' => 'smsconfig_setpaypwd' , 'value' => '設置支付密碼模板' , 'type' => 'text' , 'desc' => '' ), array ( 'name' => 'smsconfig_changemobile' , 'value' => '更改手機號碼模板' , 'type' => 'text' , 'desc' => '' ), array ( 'name' => 'smsconfig_order' , 'value' => '訂單提醒模板' , 'type' => 'text' , 'desc' => '有新訂單時,短信提醒' ), ); /** * */ class smsbao { function sendsms( $recNum , $appkey , $secretKey , $signName = '' , $param = '' , $tplcode = '' , $extend = '' , $sms_type = 'code' ) { $pa [ 'u' ] = $appkey ; $pa [ 'p' ] = md5( $secretKey ); $pa [ 'm' ] = $recNum ; $tpl = $tplcode ; $param =json_decode( $param ); foreach ( $param as $key => $val ){ if ( strpos ( $tpl , $key )){ $tpl = str_replace ( '${' . $key . '}' , $val , $tpl ); } } $pa [ 'c' ] = "【" . $signName . "】" . $tpl ; $data = array ( 'err' => '' ); if ( $ret != '0' ){ return $data [ 'err' ]=getResult( $ret ); } } /** * 發(fā)送http請求 * @access protected * @param string $url 請求地址 * @param string $param get方式請求內(nèi)容,數(shù)組形式,post方式時無效 * * @param string $data post請求方式時的內(nèi)容,get方式時無效 * @param string $method 請求方式,默認get */ function http( $url , $param , $data = '' , $method = 'GET' ){ $opts = array ( CURLOPT_TIMEOUT => 30, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, ); /* 根據(jù)請求類型設置特定參數(shù) */ $opts [CURLOPT_URL] = $url . '?' . http_build_query( $param ); if ( strtoupper ( $method ) == 'POST' ){ $opts [CURLOPT_POST] = 1; $opts [CURLOPT_POSTFIELDS] = $data ; if ( is_string ( $data )){ //發(fā)送JSON數(shù)據(jù) $opts [CURLOPT_HTTPHEADER] = array ( 'Content-Type: application/json; charset=utf-8' , 'Content-Length: ' . strlen ( $data ), ); } } /* 初始化并執(zhí)行curl請求 */ $ch = curl_init(); curl_setopt_array( $ch , $opts ); $data = curl_exec( $ch ); $error = curl_error( $ch ); curl_close( $ch ); //發(fā)生錯誤,拋出異常 if ( $error ) throw new \Exception( '請求發(fā)生錯誤:' . $error ); return $data ; } function getResult( $key ){ $rst [ '30' ] = '密碼錯誤' ; $rst [ '40' ] = '賬號不存在' ; $rst [ '41' ] = '余額不足' ; $rst [ '42' ] = '帳號過期' ; $rst [ '43' ] = 'IP地址限制' ; $rst [ '50' ] = '內(nèi)容含有敏感詞' ; $rst [ '51' ] = '手機號碼不正確' ; return $rst [ $key ]; } } ?> |
接著我們打開項目\inc\lib\sms.php文件,替換此文件中__construct函數(shù)代碼:
1
2
3
4
5
6
7
8
|
public function __construct( $sms_sp = '' ) { global $ym_sms_sp ; $sms_sp = $sms_sp == '' ? 'smsbao' : $sms_sp ; $this ->sms_sp = $sms_sp ; $ym_val =get_cache( 'sms' , cache_static, $sms_sp ); $this ->sms_config = $ym_val ; require plugin. 'sms/' . $sms_sp . '/' . $sms_sp . '.php' ; } |
最后我們在項目\inc\module\下新建smsbao_install.php文件
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?php if (!defined( 'in_mx' )) { exit ( 'Access Denied' );} $db = dbc(); global $db ; $res = $db ->insert( 'sms_config' , array ( 'code' => 'smsbao' , 'name' => '短信寶' , 'signname' => '云EC' , 'config' => '{"appkey":"","secretKey":"","reg":"${product},\u60a8\u7684\u9a8c\u8bc1\u7801\u4e3a\uff1a${code}\u6253\u6b7b\u4e5f\u4e0d\u80fd\u544a\u8bc9\u522b\u4eba\u54e6","login":"${product},\u60a8\u7684\u9a8c\u8bc1\u7801\u4e3a\uff1a${code}\u6253\u6b7b\u4e5f\u4e0d\u80fd\u544a\u8bc9\u522b\u4eba\u54e6","updatepwd":"${product},\u60a8\u7684\u9a8c\u8bc1\u7801\u4e3a\uff1a${code}\u6253\u6b7b\u4e5f\u4e0d\u80fd\u544a\u8bc9\u522b\u4eba\u54e6","setpaypwd":"${product},\u60a8\u7684\u9a8c\u8bc1\u7801\u4e3a\uff1a${code}\u6253\u6b7b\u4e5f\u4e0d\u80fd\u544a\u8bc9\u522b\u4eba\u54e6","changemobile":"${product},\u60a8\u7684\u9a8c\u8bc1\u7801\u4e3a\uff1a${code}\u6253\u6b7b\u4e5f\u4e0d\u80fd\u544a\u8bc9\u522b\u4eba\u54e6","order":"\u606d\u559c\u4f60\u4e0b\u5355\u6210\u529f\uff0c\u8ba2\u5355\u53f7\u4e3a\uff1a${order_sn},\u795d\u4f60\u8d2d\u7269\u6109\u5feb\uff01"}' , 'status' =>0)); if ( $res ){ echo '短信寶插件安裝成功,請刪除inc/module/smsbao_install.php文件' ; } else { echo '安裝失敗,請咨詢短信寶客服' ; } exit (); ?> |
經(jīng)過上面的替換,短信寶的短信平臺已經(jīng)替換成功了,可以正常使用了。進行測試發(fā)送:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會人工審核,短信內(nèi)容3~5秒就可送達。
另外:我們已經(jīng)開發(fā)好完整的云EC商城系統(tǒng)短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類