商派ecshop的短信服务二次开发
更新时间:2015-10-20 点击量:2269

土豪公司的一个土豪朋友买了商派ecshop的商业授权,激活了短信服务,但短信服务只在pc端使用。Ectouch中使用的话需要进行二次开发。
在ecshop后台的云服务中心下的短信服务中心可以找到短信接口的api,但很遗憾和ecshop中includes\cls_sms.php
使用的不同。
这里需要的是appkey及appsecret
而这里传输的是entId、entPwd参数
那么久只有按照cls_sms.php的方法组装参数,调用接口,主要参数可以在数据库中shop_config中找到:
忙了一两个小时,在Ectouch中修改完成短信类\mobile\include\library\EcsSms.class.php
,总是测试不通过,返回10021错误代码(系统错误),但在ecshop中能够正常使用。
组装的数据(敏感信息用*号代替)
Array
(
[sendType] => notice
[contents] => [{"phones":"1811***7**2","content":"\u60a8\u7684\u8ba2\u53552015091548652\u5df2\u4e8e09\u670815\u65e59\u65f6\u53d1\u8d27"}]
[certi_app] => sms.send
[entId] => 11011*******
[entPwd] => 0b643***************7****
[license] => 11****
[source] => *******
[use_backlist] => 1
[version] => 1.0
[format] => json
[timestamp] => 1442321216
[certi_ac] => f5ba*******e770*******
)
返回的数据:
Array
(
[msg] => 10021
[res] => fail
[info] => Traceback (most recent call last):
File "/data/
if not self._qianmingcheck() : return (False,10008,'qianming is error or exists')
File "/data/
print md5("smssigns_%s"%signs[0])
IndexError: list index out of range
)
看原因应该是缺少signs变量的值(IndexError:list index out of range),但抓取ecshop正常发送短信时的组装参数后,一对比没有缺少参数。最后,什么方法都用了,甚至用错误的entId和entPwd,返回值依然是一层不变的10021错误。询问商派技术人员,但人家回复不提供二次开发服务。太坑人了,一个网站难道还需要买两套短信服务吗(ecshop和Ectouch默认的短信服务都不一样)。当然也有可能是我这边错误,我菜鸟一个,大虾别喷,有开发经验的麻烦告知,感激不尽!
最后,没法,土豪朋友已经买了短信服务了。只有在ecshop下做一个接口,由Ectouch中的EcsSms.class.php调用,实现Ectouch发送短信。
- 在ecshop根目录下新建文件sendSms.php,代码如下(关键信息用*号替代,因为只是内部调用,只用了简单验证)
<?php
define('IN_ECS', true);
$key = "********";
$getKey =isset($_GET["key"])? $_GET["key"]:"";
if ($getKey == $key) {
require(dirname(__FILE__) . '/includes/init.php');
include_once('includes/cls_sms.php');
$sms = new sms();
$phones = isset($_GET["phones"])?$_GET["phones"]:"";
$msg = isset($_GET["msg"])? $_GET["msg"]:"";
$result = $sms->send($phones, $msg);
$re = array();
if (!$result) {
$re["error"] = $sms->errors["server_errors"]["error_no"];
$re["msg"] = $sms->errors["server_errors"]["error_msg"];
} else {
$re["error"] = 0;
}
} else {
$re["error"] = 3001;
$re["msg"] = "key错误";
}
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($re));
- EcsSms.class.php 中去掉无关方法,改写send 方法。
function send($phones,$msg,$send_date = '', $send_num = 1,$sms_type='',$version='1.0', &$sms_error = '')
{
//$msg="您的订单2015091548652已于09月15日9时发货 ";
$url=";;
$response=file_get_contents($url);
$result=json_decode($response,true);
if(isset($result["error"]) && $result["error"]==0){
return true;
}else{
$sms_error=$result["error"].$result["msg"];
return false;
}
}
搞定,菜鸟一个还望童鞋们多多指教。
如果文章对您有帮助,就打赏一个吧
«上一篇:apache启用mod_expires或mod_headers设置静态文件缓存时间 下一篇:Ectouch中缓存管理函数»