[转]人人店短信插件开发
本文转自:https://blog.csdn.net/mindev/article/details/75088344
人人商城是一款针对的移动端购物消费的微信商城管理系统。它不仅能为您提供专业可靠的技术支持,还能完美适配企业商用。可添加多个公众号使用,具有强大的自定义功能,让您拥有个性化商城。本人对该系统还是比较熟悉的,今天我就来分享一下,如何进行二次开发。我以替换短信接口为例,一步一步的手把手教大家开发过程。
短信接口使用的是短信宝短信平台的短信接口,小伙伴一定会问为什么使用短信宝作为案例呢?原因很简单,因为短信宝的平台极其稳定,而且短信发送速度相当快捷,验证码和订单通知在3~5秒就能收到,用户体验非常好,所以我们公司一直和短信宝保持着合作关系,小伙伴们也可以去短信宝的官网(http://www.smsbao.com)注册一个账号,还有免费的短信条数送呢。
接下来我就说一下开发步骤: 1。先打开项目/core/com/sms.php文件,添加短信宝的发送接口代码:
<?php
if (!defined('IN_IA'))
{
exit('Access Denied');
}
class Sms_EweiShopV2ComModel extends ComModel
{
public function send($mobile, $tplid, $data, $replace = true)
{
global $_W;
$smsset = $this->sms_set();
$template = $this->sms_verify($tplid, $smsset);
if (empty($template['status']))
{
return $template;
}
$params = $this->sms_data($template['type'], $data, $replace, $template);
if ($template['type'] == 'juhe')
{
$data = array('mobile' => $mobile, 'tpl_id' => $template['smstplid'], 'tpl_value' => $params, 'key' => $smsset['juhe_key']);
$result = $this->http_post('http://v.juhe.cn/sms/send', $data);
if (empty($result) || (0 < $result['error_code']))
{
return array('status' => 0, 'message' => '短信发送失败(' . $result['error_code'] . '):' . $result['reason']);
}
}
if ($template['type'] == 'smsbao') {
$results = array(
'30' => '密码错误',
'40' => '账号不存在',
'41' => '余额不足',
'42' => '帐号过期',
'43' => 'IP地址限制',
'50' => '内容含有敏感词',
'51' => '手机号码不正确'
);
$url = 'http://api.smsbao.com/sms?u='.$smsset['smsbao_key'].'&p='.md5($smsset['smsbao_secret']).'&m='.$mobile.'&c='.'【'.$smsset['smsbao_sign'].'】'.$params;
$res = file_get_contents($url);
if ($res != 0) {
return array('status' => $res, 'message' => $results[$res]);
}
}
if ($template['type'] == 'dayu')
{
include_once EWEI_SHOPV2_VENDOR . 'dayu/TopSdk.php';
$dayuClient = new TopClient();
$dayuClient->appkey = $smsset['dayu_key'];
$dayuClient->secretKey = $smsset['dayu_secret'];
$dayuRequest = new AlibabaAliqinFcSmsNumSendRequest();
$dayuRequest->setSmsType('normal');
$dayuRequest->setSmsFreeSignName($template['smssign']);
$dayuRequest->setSmsParam($params);
$dayuRequest->setRecNum('' . $mobile);
$dayuRequest->setSmsTemplateCode($template['smstplid']);
$dayuResult = $dayuClient->execute($dayuRequest);
$dayuResult = (array) $dayuResult;
if (empty($dayuResult) || !empty($dayuResult['code']))
{
return array('status' => 0, 'message' => '短信发送失败(' . $dayuResult['sub_msg'] . '/code: ' . $dayuResult['code'] . '/sub_code: ' . $dayuResult['sub_code'] . ')');
}
}
if ($template['type'] == 'emay')
{
include_once EWEI_SHOPV2_VENDOR . 'emay/SMSUtil.php';
$balance = $this->sms_num('emay', $smsset);
if ($balance <= 0)
{
return array('status' => 0, 'message' => '短信发送失败(亿美软通余额不足, 当前余额' . $balance . ')');
}
$emayClient = new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
$emayResult = $emayClient->send($mobile, '【' . $template['smssign'] . '】' . $params);
if (!empty($emayResult))
{
return array('status' => 0, 'message' =>