云EC商城系統是安全,快捷,高效商城系統,擁有積分、限量優惠(秒殺)、拼團、分銷、優惠券等精準營銷利器的電商系統,還有虛擬銷量和后臺批量評價。小編對他還是很了解,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,我們今天講解的是V1.3版本,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
1:打開項目:\inc\module 新增smsbao_install.php 在數據庫插入短信寶相關字段
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?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(); ?> |
2:打開項目:\inc\plugin\sms 新增smsbao文件夾 在smsbao文件夾下面新增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
|
<?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); } } /** * 發送http請求 * @access protected * @param string $url 請求地址 * @param string $param get方式請求內容,數組形式,post方式時無效 * * @param string $data post請求方式時的內容,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 , ); /* 根據請求類型設置特定參數 */ $opts[CURLOPT_URL] = $url . '?' . http_build_query($param); if (strtoupper($method) == 'POST' ){ $opts[CURLOPT_POST] = 1; $opts[CURLOPT_POSTFIELDS] = $data; if (is_string($data)){ //發送JSON數據 $opts[CURLOPT_HTTPHEADER] = array( 'Content-Type: application/json; charset=utf-8' , 'Content-Length: ' . strlen($data), ); } } /* 初始化并執行curl請求 */ $ch = curl_init(); curl_setopt_array($ch, $opts); $data = curl_exec($ch); $error = curl_error($ch); curl_close($ch); //發生錯誤,拋出異常 if ($error) throw new \Exception( '請求發生錯誤:' . $error); return $data; } function getResult($key){ $rst[ '30' ] = '密碼錯誤' ; $rst[ '40' ] = '賬號不存在' ; $rst[ '41' ] = '余額不足' ; $rst[ '42' ] = '帳號過期' ; $rst[ '43' ] = 'IP地址限制' ; $rst[ '50' ] = '內容含有敏感詞' ; $rst[ '51' ] = '手機號碼不正確' ; return $rst[$key]; } } ?> |
3:打開項目:\inc\lib\sms.php 修改大概18行左右
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' ; } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的云EC電商系統系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類