在非composer下引入阿里云短信,人人商城引入阿里云短信,人人分销引入阿里云短信接口:
#### 人人商城接入阿里云短信
1、更新SQL:
ALTER TABLE `ims_ewei_shop_sms_set`
ADD COLUMN `aliyun_accesskeyid` varchar(255) NULL DEFAULT '' COMMENT '阿里云AccessKeyId' AFTER `aliyun_appcode`,
ADD COLUMN `aliyun_accesssecret` varchar(255) NULL DEFAULT '' COMMENT '阿里云AccessSecret' AFTER `aliyun_accesskeyid`;
2、下载API接口:
下载后解压将文件夹复制到addons/ewei_shopv2/vendor/aliyunsms目录下。
并在文件夹下添加Api.php文件,内容如下:
<?php
/**
* Created by dutuwang.com
* User: adophper
* Date: 2020/3/27
* Time: 11:08 PM
*/
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloudClientAlibabaCloud;
use AlibabaCloudClientExceptionClientException;
use AlibabaCloudClientExceptionServerException;
/**
* Class Api
*/
class Api
{
/**
* @param $config
* @param $mobile
* @param $template
* @param $params
* @return array
* @throws ClientException
*/
public function sendCode($config, $mobile, $template, $params){
AlibabaCloud::accessKeyClient($config['aliyun_accesskeyid'], $config['aliyun_accesssecret'])->regionId('cn-hangzhou')->asDefaultClient();
try {
$request = AlibabaCloud::rpc()
->product('Dysmsapi')
// ->scheme('https') // https | http
->version('2017-05-25')
->action('SendSms')
->method('POST')
->host('dysmsapi.aliyuncs.com')
->options([
'query' => [
'RegionId' => "cn-hangzhou",
'PhoneNumbers' => $mobile,
'SignName' => $template['smssign'],
'TemplateCode' => $template['smstplid'],
'TemplateParam' => $params,
'OutId' => "jiahe_",
],
])->request();
$result = $request->toArray();
if ($result['Code'] != 'OK') {
return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $result['Message'] . ')');
}else{
return array('status' => 1, 'message' => 'OK');
}
} catch (ClientException $e) {
// echo $e->getErrorMessage() . PHP_EOL;
return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $e->getErrorMessage() . ')');
} catch (ServerException $e) {
// echo $e->getErrorMessage() . PHP_EOL;
return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $e->getErrorMessage() . ')');
}
}
}
3、修改发送短信方法:
addons/ewei_shopv2/core/com/sms.php
第一处:
if (empty($smsset['aliyun_appcode']))
{
return array('status' => 0, 'message' => '未填写阿里云短信AppCode!');
}
改为
if (empty($smsset['aliyun_accesskeyid']))
{
return array('status' => 0, 'message' => '未填写阿里云短信AccessKeyId!');
}
if (empty($smsset['aliyun_accesssecret']))
{
return array('status' => 0, 'message' => '未填写阿里云短信AccessSecret!');
}
第二处:
load()->func('communication');
$paramstr = http_build_query(array('ParamString' => $params, 'RecNum' => $mobile, 'SignName' => $template['smssign'], 'TemplateCode' => $template['smstplid']));
$header = array('Authorization' => 'APPCODE ' . $smsset['aliyun_appcode']);
$request = ihttp_request('http://sms.market.alicloudapi.com/singleSendSms?' . $paramstr, '', $header);
$result = json_decode($request['content'], true);
if (!($result['success']) || ($request['code'] != 200))
{
if ($request['code'] != 200)
{
$result['message'] = $request['headers']['X-Ca-Error-Message'];
}
return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $result['message'] . ')');
}
修改为:
include_once EWEI_SHOPV2_VENDOR . 'aliyunsms/Api.php';
$result = (new Api())->sendCode($smsset, $mobile, $template, $params);
if (!isset($result['status']) || !$result['status']) {
return $result;
}
4、修改后台阿里云短信设置模板:
addons/ewei_shopv2/template/web_v3/sysset/sms/set.html
修改保存代码,注意是在aliyun_appcode后加了两行:
'aliyun_appcode' => trim($_GPC['aliyun_appcode']),
'aliyun_accesskeyid' => trim($_GPC['aliyun_accesskeyid']),
'aliyun_accesssecret' => trim($_GPC['aliyun_accesssecret']),