You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
616 lines
16 KiB
616 lines
16 KiB
<?php
|
|
namespace app\massage\model;
|
|
|
|
use AlibabaCloud\Client\AlibabaCloud;
|
|
use app\BaseModel;
|
|
use Exception;
|
|
use longbingcore\wxcore\Moor;
|
|
use think\facade\Db;
|
|
|
|
class ShortCodeConfig extends BaseModel
|
|
{
|
|
//定义表名
|
|
protected $name = 'massage_short_code_config';
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:04
|
|
* @功能说明:添加
|
|
*/
|
|
public function dataAdd($data){
|
|
|
|
$res = $this->insert($data);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:05
|
|
* @功能说明:编辑
|
|
*/
|
|
public function dataUpdate($dis,$data){
|
|
|
|
$res = $this->where($dis)->update($data);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:06
|
|
* @功能说明:列表
|
|
*/
|
|
public function dataList($dis,$page){
|
|
|
|
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:43
|
|
* @功能说明:
|
|
*/
|
|
public function dataInfo($dis){
|
|
|
|
$data = $this->where($dis)->find();
|
|
|
|
if(empty($data)){
|
|
|
|
$this->dataAdd($dis);
|
|
|
|
$data = $this->where($dis)->find();
|
|
|
|
}
|
|
|
|
return !empty($data)?$data->toArray():[];
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $uniacid
|
|
* @功能说明:
|
|
* @author chenniang
|
|
* @DataTime: 2023-02-03 10:39
|
|
*/
|
|
public function initData($uniacid){
|
|
|
|
$data = $this->dataInfo(['uniacid'=>$uniacid]);
|
|
|
|
$config_model = new Config();
|
|
|
|
$config = $config_model->dataInfo(['uniacid'=>$uniacid]);
|
|
//开始初始化
|
|
if(!empty($config['short_sign'])){
|
|
|
|
$update = [
|
|
|
|
'short_sign' => $config['short_sign'],
|
|
'order_short_code' => $config['order_short_code'],
|
|
'refund_short_code' => $config['refund_short_code'],
|
|
'help_short_code' => $config['help_short_code'],
|
|
'short_code' => $config['short_code'],
|
|
'short_code_status' => $config['short_code_status'],
|
|
];
|
|
|
|
$this->dataUpdate(['id'=>$data['id']],$update);
|
|
|
|
$prefix = longbing_get_prefix();
|
|
//执行sql删除废弃字段
|
|
$sql = <<<updateSql
|
|
|
|
ALTER TABLE `{$prefix}shequshop_school_config` DROP COLUMN `short_sign`;
|
|
ALTER TABLE `{$prefix}shequshop_school_config` DROP COLUMN `order_short_code`;
|
|
ALTER TABLE `{$prefix}shequshop_school_config` DROP COLUMN `refund_short_code`;
|
|
ALTER TABLE `{$prefix}shequshop_school_config` DROP COLUMN `help_short_code`;
|
|
ALTER TABLE `{$prefix}shequshop_school_config` DROP COLUMN `short_code`;
|
|
ALTER TABLE `{$prefix}shequshop_school_config` DROP COLUMN `short_code_status`;
|
|
|
|
|
|
updateSql;
|
|
|
|
$sql = str_replace(PHP_EOL, '', $sql);
|
|
$sqlArray = explode(';', $sql);
|
|
|
|
foreach ($sqlArray as $_value) {
|
|
if(!empty($_value)){
|
|
|
|
try{
|
|
Db::query($_value) ;
|
|
}catch (\Exception $e){
|
|
if (!APP_DEBUG){
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-04-19 15:13
|
|
* @功能说明:七莫发送订单通知
|
|
*/
|
|
public function sendSmsMoor($str_phone,$uniacid,$order_code,$type=1){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
if($type==1){
|
|
|
|
$TemplateCode = trim($config['moor_order_short_code']);
|
|
|
|
}else{
|
|
|
|
$TemplateCode = trim($config['moor_refund_short_code']);
|
|
|
|
}
|
|
|
|
$moor = new Moor($uniacid);
|
|
|
|
$res = $moor->sendShortMsg($str_phone,['var1'=>$order_code],$TemplateCode);
|
|
|
|
return $res;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-04-19 15:01
|
|
* @功能说明:发送短信验证码
|
|
*/
|
|
public function sendSms($str_phone,$uniacid,$order_code,$type=1){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
if($config['type']==1){
|
|
|
|
$res = $this->sendSmsAliyun($str_phone,$uniacid,$order_code,$type);
|
|
|
|
}else{
|
|
|
|
$res = $this->sendSmsMoor($str_phone,$uniacid,$order_code,$type);
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $str_phone
|
|
* @param $uniacid
|
|
* @功能说明:发送短信验证码
|
|
* @author chenniang
|
|
* @DataTime: 2022-03-14 10:43
|
|
*/
|
|
public function sendSmsAliyun($str_phone,$uniacid,$order_code,$type=1){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
$setting_model = new Config();
|
|
|
|
$setting = $setting_model->dataInfo($dis);
|
|
|
|
$keyId = trim($setting['short_id']);
|
|
|
|
$keySecret = trim($setting['short_secret']);
|
|
|
|
$SignName = trim($config['short_sign']);
|
|
|
|
if($type==1){
|
|
|
|
$TemplateCode = trim($config['order_short_code']);
|
|
|
|
}else{
|
|
|
|
$TemplateCode = trim($config['refund_short_code']);
|
|
|
|
}
|
|
|
|
if(empty($keyId)||empty($keySecret)||empty($TemplateCode)){
|
|
|
|
return false;
|
|
}
|
|
|
|
AlibabaCloud::accessKeyClient($keyId, $keySecret)->regionId('cn-hangzhou') // replace regionId as you need
|
|
->asDefaultClient();
|
|
|
|
try {
|
|
$result = AlibabaCloud::rpc()
|
|
->product('Dysmsapi')
|
|
// ->scheme('https') // https | http
|
|
->version('2017-05-25')
|
|
->action('SendSms')
|
|
->method('POST')
|
|
->host('dysmsapi.aliyuncs.com')
|
|
->options([
|
|
'query' => [
|
|
'RegionId' => "default",
|
|
'PhoneNumbers' => $str_phone,
|
|
//必填项 签名(需要在阿里云短信服务后台申请)
|
|
'SignName' => $SignName,
|
|
//必填项 短信模板code (需要在阿里云短信服务后台申请)
|
|
'TemplateCode' => $TemplateCode,
|
|
//如果在短信中添加了${code} 变量则此项必填 要求为JSON格式
|
|
'TemplateParam' => "{'name':$order_code}",
|
|
],
|
|
])
|
|
->request();
|
|
|
|
return !empty($result)?$result->toArray():[];
|
|
} catch(Exception $e)
|
|
{}
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-04-19 15:01
|
|
* @功能说明:发送短信验证码
|
|
*/
|
|
public function sendSmsCode($str_phone,$uniacid,$key=''){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
if($config['type']==1){
|
|
|
|
$res = $this->sendSmsCodeAliyun($str_phone,$uniacid,$key);
|
|
|
|
}else{
|
|
|
|
$res = $this->sendSmsCodeMoor($str_phone,$uniacid,$key);
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @param $str_phone
|
|
* @param $uniacid
|
|
* @功能说明:发送短信验证码
|
|
* @author chenniang
|
|
* @DataTime: 2022-03-14 10:43
|
|
*/
|
|
public function sendSmsCodeAliyun($str_phone,$uniacid,$key=''){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
$setting_model = new Config();
|
|
|
|
$setting = $setting_model->dataInfo($dis);
|
|
|
|
$keyId = trim($setting['short_id']);
|
|
|
|
$keySecret = trim($setting['short_secret']);
|
|
|
|
$SignName = $config['short_sign'];
|
|
|
|
$TemplateCode = $config['short_code'];
|
|
|
|
if(empty($keyId)||empty($keySecret)||empty($TemplateCode)){
|
|
|
|
return false;
|
|
}
|
|
$code = mt_rand(100000,999999);
|
|
|
|
setCache($str_phone.$key,$code,60,$uniacid);
|
|
|
|
AlibabaCloud::accessKeyClient($keyId, $keySecret)->regionId('cn-hangzhou') // replace regionId as you need
|
|
->asDefaultClient();
|
|
|
|
try {
|
|
|
|
$result = AlibabaCloud::rpc()
|
|
->product('Dysmsapi')
|
|
// ->scheme('https') // https | http
|
|
->version('2017-05-25')
|
|
->action('SendSms')
|
|
->method('POST')
|
|
->host('dysmsapi.aliyuncs.com')
|
|
->options([
|
|
'query' => [
|
|
'RegionId' => "default",
|
|
'PhoneNumbers' => $str_phone,
|
|
//必填项 签名(需要在阿里云短信服务后台申请)
|
|
'SignName' => $SignName,
|
|
//必填项 短信模板code (需要在阿里云短信服务后台申请)
|
|
'TemplateCode' => $TemplateCode,
|
|
//如果在短信中添加了${code} 变量则此项必填 要求为JSON格式
|
|
'TemplateParam' => "{'code':$code}",
|
|
],
|
|
])
|
|
->request();
|
|
return !empty($result)?$result->toArray():[];
|
|
} catch(Exception $e)
|
|
{}
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $str_phone
|
|
* @param $uniacid
|
|
* @功能说明:发送短信验证码
|
|
* @author chenniang
|
|
* @DataTime: 2022-03-14 10:43
|
|
*/
|
|
public function sendSmsCodeMoor($str_phone,$uniacid,$key=''){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
$TemplateCode = $config['moor_short_code'];
|
|
|
|
if(empty($TemplateCode)){
|
|
|
|
return false;
|
|
}
|
|
$code = mt_rand(100000,999999);
|
|
|
|
setCache($str_phone.$key,$code,60,$uniacid);
|
|
|
|
$moor = new Moor($uniacid);
|
|
|
|
$res = $moor->sendShortMsg($str_phone,['var1'=>$code],$TemplateCode);
|
|
|
|
return $res;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-04-19 15:01
|
|
* @功能说明:发送短信验证码
|
|
*/
|
|
public function sendHelpCode($uniacid,$coach_id,$address){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
if($config['type']==1){
|
|
|
|
$res = $this->sendHelpCodeAliyun($uniacid,$coach_id,$address);
|
|
|
|
}else{
|
|
|
|
$res = $this->sendHelpCodeMoor($uniacid,$coach_id,$address);
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
/**
|
|
* @param $str_phone
|
|
* @param $uniacid
|
|
* @功能说明:发送求救通知
|
|
* @author chenniang
|
|
* @DataTime: 2022-03-14 10:43
|
|
*/
|
|
public function sendHelpCodeAliyun($uniacid,$coach_id,$address){
|
|
|
|
$address = !empty($address)?$address:'暂无';
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
$setting_model = new Config();
|
|
|
|
$setting = $setting_model->dataInfo($dis);
|
|
|
|
$keyId = trim($setting['short_id']);
|
|
|
|
$keySecret = trim($setting['short_secret']);
|
|
|
|
$SignName = $config['short_sign'];
|
|
|
|
$TemplateCode = $config['help_short_code'];
|
|
|
|
if(empty($keyId)||empty($keySecret)||empty($TemplateCode)){
|
|
|
|
return false;
|
|
}
|
|
|
|
$help_cofig_model = new HelpConfig();
|
|
|
|
$str_phone = $help_cofig_model->where(['uniacid'=>$uniacid])->value('help_phone');
|
|
|
|
if(empty($str_phone)){
|
|
|
|
return false;
|
|
}
|
|
|
|
$coach_model= new Coach();
|
|
|
|
$coach_name= $coach_model->where(['id'=>$coach_id])->value('coach_name');
|
|
|
|
AlibabaCloud::accessKeyClient($keyId, $keySecret)->regionId('cn-hangzhou') // replace regionId as you need
|
|
->asDefaultClient();
|
|
|
|
try {
|
|
$result = AlibabaCloud::rpc()
|
|
->product('Dysmsapi')
|
|
// ->scheme('https') // https | http
|
|
->version('2017-05-25')
|
|
->action('SendSms')
|
|
->method('POST')
|
|
->host('dysmsapi.aliyuncs.com')
|
|
->options([
|
|
'query' => [
|
|
'RegionId' => "default",
|
|
'PhoneNumbers' => $str_phone,
|
|
//必填项 签名(需要在阿里云短信服务后台申请)
|
|
'SignName' => $SignName,
|
|
//必填项 短信模板code (需要在阿里云短信服务后台申请)
|
|
'TemplateCode' => $TemplateCode,
|
|
//如果在短信中添加了${code} 变量则此项必填 要求为JSON格式
|
|
//'TemplateParam' => "{'name':$coach_name,'address':$address}",
|
|
|
|
'TemplateParam' => json_encode(['name'=>$coach_name.'(ID:'.$coach_id.')','address'=>$address]),
|
|
],
|
|
])
|
|
->request();
|
|
|
|
|
|
return !empty($result)?$result->toArray():[];
|
|
} catch(Exception $e)
|
|
{}
|
|
}
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-04-19 15:13
|
|
* @功能说明:七莫发送订单通知
|
|
*/
|
|
public function sendHelpCodeMoor($uniacid,$coach_id,$address){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $uniacid
|
|
];
|
|
|
|
$config = $this->dataInfo($dis);
|
|
|
|
$help_cofig_model = new HelpConfig();
|
|
|
|
$str_phone = $help_cofig_model->where(['uniacid'=>$uniacid])->value('help_phone');
|
|
|
|
$TemplateCode = trim($config['moor_help_short_code']);
|
|
|
|
$coach_model= new Coach();
|
|
|
|
$coach_name= $coach_model->where(['id'=>$coach_id])->value('coach_name');
|
|
|
|
$moor = new Moor($uniacid);
|
|
|
|
$res = $moor->sendShortMsg($str_phone,['var1'=>$coach_name.'(ID:'.$coach_id.')','var2'=>$address],$TemplateCode);
|
|
|
|
return $res;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-05-24 11:44
|
|
* @功能说明:登录短信验证
|
|
*/
|
|
public function loginShortConfig($phone,$uniacid){
|
|
|
|
$config = $this->dataInfo(['uniacid'=>$uniacid]);
|
|
//用自己的短信
|
|
if($config['short_code_status']==1){
|
|
|
|
$result = $this->sendSmsCode($phone,$uniacid,'login');
|
|
|
|
}else{
|
|
//如果没有配置将用公司的
|
|
$keyId = 'LTAI5tFrj719QhX4w8yHxiZU';
|
|
|
|
$keySecret = '7ReHO5inoSeLxU8RqmQRpAeRwkaxkb';
|
|
|
|
$SignName = '龙兵智能名片';
|
|
|
|
$TemplateCode = 'SMS_251600790';
|
|
|
|
if(empty($keyId)||empty($keySecret)||empty($TemplateCode)){
|
|
|
|
return false;
|
|
}
|
|
$code = mt_rand(100000,999999);
|
|
|
|
setCache($phone.'login',$code,60,$uniacid);
|
|
|
|
AlibabaCloud::accessKeyClient($keyId, $keySecret)->regionId('cn-hangzhou') // replace regionId as you need
|
|
->asDefaultClient();
|
|
|
|
try {
|
|
$result = AlibabaCloud::rpc()
|
|
->product('Dysmsapi')
|
|
// ->scheme('https') // https | http
|
|
->version('2017-05-25')
|
|
->action('SendSms')
|
|
->method('POST')
|
|
->host('dysmsapi.aliyuncs.com')
|
|
->options([
|
|
'query' => [
|
|
'RegionId' => "default",
|
|
'PhoneNumbers' => $phone,
|
|
//必填项 签名(需要在阿里云短信服务后台申请)
|
|
'SignName' => $SignName,
|
|
//必填项 短信模板code (需要在阿里云短信服务后台申请)
|
|
'TemplateCode' => $TemplateCode,
|
|
//如果在短信中添加了${code} 变量则此项必填 要求为JSON格式
|
|
'TemplateParam' => "{'code':$code}",
|
|
],
|
|
])
|
|
->request();
|
|
|
|
|
|
return !empty($result)?$result->toArray():[];
|
|
} catch(Exception $e)
|
|
{}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
|
|
|
|
} |