834 lines
32 KiB
PHP
834 lines
32 KiB
PHP
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: abcdefg
|
||
* Date: 2017/10/9
|
||
* Time: 11:37
|
||
*/
|
||
|
||
require_once dirname(dirname(__DIR__)) . '/common/ErrorType.php';
|
||
require_once dirname(dirname(__DIR__)) . '/common/common.inc.php';
|
||
require_once dirname(dirname(__DIR__)) . '/common/BaseMethodHelper.php';
|
||
//require_once dirname(dirname(__DIR__)) . '/third/taobao/topsdk.php';
|
||
require_once dirname(dirname(__DIR__)) . '/third/dysms/api_demo/smsdemo.php';
|
||
|
||
class sms extends BaseMethod
|
||
{
|
||
//会员名:tsys0606
|
||
//密码:lili12881589
|
||
//验证手机号码:黄会计 13807081266
|
||
//https://dayu.aliyun.com/
|
||
|
||
|
||
/// xc8589@sina.com
|
||
/// tswl0791
|
||
/// Access Key ID: wU1zLTU3k3W0olIt
|
||
/// Access Key Secret: muQA0NFojzEqbyX81vfBHdTYcK7Pwk
|
||
|
||
const SMS_APPKEY = '24646920'; /// appkey
|
||
const SMS_SECRETKEY = 'b61d3756d66a48a9316726833c677b2c'; /// secretkey
|
||
//const SMS_SIGNNAME = '阿里大于测试专用'; /// 签名
|
||
const SMS_SIGNNAME = '天盛网络';
|
||
|
||
const SMS_ACCESSKEYID = 'wU1zLTU3k3W0olIt';
|
||
const SMS_ACCESSKEYSECRET = 'muQA0NFojzEqbyX81vfBHdTYcK7Pwk';
|
||
/*
|
||
const SMSINDEX_INFORMATION_CHANGED = 1; /// 信息变更验证码(验证码${code},您正在尝试变更${product}重要信息,请妥善保管账户信息。)
|
||
const SMSINDEX_CHANGE_PASSWORD = 2; /// 修改密码验证码(验证码${code},您正在尝试修改${product}登录密码,请妥善保管账户信息。)
|
||
const SMSINDEX_ACTIVITY_CONFIRMATION = 3; /// 活动确认验证码(验证码${code},您正在参加${product}的${item}活动,请确认系本人申请。)
|
||
const SMSINDEX_USER_REGISTRATION = 4; /// 用户注册验证码(验证码${code},您正在注册成为${product}用户,感谢您的支持!)
|
||
const SMSINDEX_LOGIN_EXCEPTION = 5; /// 登录异常验证码(验证码${code},您正尝试异地登录${product},若非本人操作,请勿泄露。)
|
||
const SMSINDEX_LOGIN_CONFIRMATION = 6; /// 登录确认验证码(验证码${code},您正在登录${product},若非本人操作,请勿泄露。)
|
||
const SMSINDEX_SMS_TEST = 7; /// 短信测试(尊敬的${customer},欢迎您使用阿里大鱼短信服务,阿里大鱼将为您提供便捷的通信服务!)
|
||
const SMSINDEX_AUTHENTICATION = 8; /// 身份验证验证码(验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!)
|
||
*/
|
||
|
||
const SMSINDEX_INFORMATION_CHANGED = 1; /// 信息变更验证码(验证码${code},您正在尝试变更重要信息,请妥善保管账户信息。)
|
||
const SMSINDEX_CHANGE_PASSWORD = 2; /// 修改密码验证码(验证码${code},您正在尝试修改登录密码,请妥善保管账户信息。)
|
||
const SMSINDEX_USER_REGISTRATION = 3; /// 用户注册验证码(验证码${code},您正在注册成为新用户,感谢您的支持!)
|
||
const SMSINDEX_LOGIN_EXCEPTION = 4; /// 登录异常验证码(验证码${code},您正尝试异地登录,若非本人操作,请勿泄露。)
|
||
const SMSINDEX_LOGIN_CONFIRMATION = 5; /// 登录确认验证码(验证码${code},您正在登录,若非本人操作,请勿泄露。)
|
||
const SMSINDEX_SMS_TEST = 6; /// 短信测试(尊敬的${customer},欢迎您使用阿里云通信服务!)
|
||
const SMSINDEX_AUTHENTICATION = 7; /// 身份验证验证码(验证码${code},您正在进行身份验证,打死不要告诉别人哦!)
|
||
|
||
private function GetSmsTemplateCode($Index)
|
||
{
|
||
switch ($Index)
|
||
{
|
||
/*
|
||
case self::SMSINDEX_INFORMATION_CHANGED: /// 信息变更验证码(验证码${code},您正在尝试变更${product}重要信息,请妥善保管账户信息。)
|
||
return 'SMS_70060714';
|
||
case self::SMSINDEX_CHANGE_PASSWORD: /// 修改密码验证码(验证码${code},您正在尝试修改${product}登录密码,请妥善保管账户信息。)
|
||
return 'SMS_70060715';
|
||
case self::SMSINDEX_ACTIVITY_CONFIRMATION: /// 活动确认验证码(验证码${code},您正在参加${product}的${item}活动,请确认系本人申请。)
|
||
return 'SMS_70060716';
|
||
case self::SMSINDEX_USER_REGISTRATION: /// 用户注册验证码(验证码${code},您正在注册成为${product}用户,感谢您的支持!)
|
||
return 'SMS_70060717';
|
||
case self::SMSINDEX_LOGIN_EXCEPTION: /// 登录异常验证码(验证码${code},您正尝试异地登录${product},若非本人操作,请勿泄露。)
|
||
return 'SMS_70060718';
|
||
case self::SMSINDEX_LOGIN_CONFIRMATION: /// 登录确认验证码(验证码${code},您正在登录${product},若非本人操作,请勿泄露。)
|
||
return 'SMS_70060719';
|
||
case self::SMSINDEX_SMS_TEST: /// 短信测试(尊敬的${customer},欢迎您使用阿里大鱼短信服务,阿里大鱼将为您提供便捷的通信服务!)
|
||
return 'SMS_70060720';
|
||
case self::SMSINDEX_AUTHENTICATION: /// 身份验证验证码(验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!)
|
||
return 'SMS_70060721';
|
||
*/
|
||
|
||
case self::SMSINDEX_INFORMATION_CHANGED: /// 信息变更验证码(验证码${code},您正在尝试变更重要信息,请妥善保管账户信息。)
|
||
return 'SMS_104940057';
|
||
case self::SMSINDEX_CHANGE_PASSWORD: /// 修改密码验证码(验证码${code},您正在尝试修改登录密码,请妥善保管账户信息。)
|
||
return 'SMS_104940058';
|
||
case self::SMSINDEX_USER_REGISTRATION: /// 用户注册验证码(验证码${code},您正在注册成为新用户,感谢您的支持!)
|
||
return 'SMS_104940059';
|
||
case self::SMSINDEX_LOGIN_EXCEPTION: /// 登录异常验证码(验证码${code},您正尝试异地登录,若非本人操作,请勿泄露。)
|
||
return 'SMS_104940060';
|
||
case self::SMSINDEX_LOGIN_CONFIRMATION: /// 登录确认验证码(验证码${code},您正在登录,若非本人操作,请勿泄露。)
|
||
return 'SMS_104940061';
|
||
case self::SMSINDEX_SMS_TEST: /// 短信测试(尊敬的${customer},欢迎您使用阿里云通信服务!)
|
||
return 'SMS_104940062';
|
||
case self::SMSINDEX_AUTHENTICATION: /// 身份验证验证码(验证码${code},您正在进行身份验证,打死不要告诉别人哦!)
|
||
return 'SMS_104940063';
|
||
|
||
default:
|
||
return 'unknown';
|
||
}
|
||
}
|
||
|
||
private function GetSmsTemplateParameter($Index, $Parameter)
|
||
{
|
||
if (!is_array($Parameter))
|
||
$Parameter = (array)$Parameter;
|
||
/*
|
||
switch ($Index)
|
||
{
|
||
case self::SMSINDEX_INFORMATION_CHANGED: /// 信息变更验证码(验证码${code},您正在尝试变更${product}重要信息,请妥善保管账户信息。)
|
||
return "{code:'{$Parameter['code']}',product:'{$Parameter['product']}'}";
|
||
case self::SMSINDEX_CHANGE_PASSWORD: /// 修改密码验证码(验证码${code},您正在尝试修改${product}登录密码,请妥善保管账户信息。)
|
||
return "{code:'{$Parameter['code']}',product:'{$Parameter['product']}'}";
|
||
case self::SMSINDEX_ACTIVITY_CONFIRMATION: /// 活动确认验证码(验证码${code},您正在参加${product}的${item}活动,请确认系本人申请。)
|
||
return "{code:'{$Parameter['code']}',product:'{$Parameter['product']}',item:'{$Parameter['item']}'}";
|
||
case self::SMSINDEX_USER_REGISTRATION: /// 用户注册验证码(验证码${code},您正在注册成为${product}用户,感谢您的支持!)
|
||
return "{code:'{$Parameter['code']}',product:'{$Parameter['product']}'}";
|
||
case self::SMSINDEX_LOGIN_EXCEPTION: /// 登录异常验证码(验证码${code},您正尝试异地登录${product},若非本人操作,请勿泄露。)
|
||
return "{code:'{$Parameter['code']}',product:'{$Parameter['product']}'}";
|
||
case self::SMSINDEX_LOGIN_CONFIRMATION: /// 登录确认验证码(验证码${code},您正在登录${product},若非本人操作,请勿泄露。)
|
||
return "{code:'{$Parameter['code']}',product:'{$Parameter['product']}'}";
|
||
case self::SMSINDEX_SMS_TEST: /// 短信测试(尊敬的${customer},欢迎您使用阿里大鱼短信服务,阿里大鱼将为您提供便捷的通信服务!)
|
||
return "{customer:'{$Parameter['customer']}'}";
|
||
case self::SMSINDEX_AUTHENTICATION: /// 身份验证验证码(验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!)
|
||
return "{code:'{$Parameter['code']}',product:'{$Parameter['product']}'}";
|
||
default:
|
||
return 'unknown';
|
||
}
|
||
*/
|
||
return JsonObjectToJsonString($Parameter);
|
||
}
|
||
|
||
/**
|
||
* @note 发送短信(淘宝接口)
|
||
* @param integer $SmsTemplateCodeIndex 模板序号
|
||
* @param array $SmsTemplateParameter 短信参数
|
||
* @param string $Telphone 电话号码
|
||
* @return bool
|
||
*/
|
||
private function _SendMessage($SmsTemplateCodeIndex, $SmsTemplateParameter, $Telphone)
|
||
{
|
||
$Client = new TopClient(self::SMS_APPKEY, self::SMS_SECRETKEY);
|
||
|
||
$SmsRequest = new AlibabaAliqinFcSmsNumSendRequest();
|
||
$SmsRequest->setExtend('');
|
||
$SmsRequest->setSmsType('normal');
|
||
$SmsRequest->setSmsFreeSignName(self::SMS_SIGNNAME);
|
||
$SmsRequest->setSmsParam($this->GetSmsTemplateParameter($SmsTemplateCodeIndex, $SmsTemplateParameter));
|
||
$SmsRequest->setRecNum($Telphone);
|
||
$SmsRequest->setSmsTemplateCode($this->GetSmsTemplateCode($SmsTemplateCodeIndex));
|
||
$SmsReturn = $Client->execute($SmsRequest)->result;
|
||
|
||
if (!empty($SmsReturn->success))
|
||
{
|
||
if (strcasecmp($SmsReturn->success, 'true') == 0)
|
||
return null;
|
||
elseif (!empty($SmsReturn->msg))
|
||
return $SmsReturn->msg;
|
||
else
|
||
return null;
|
||
}
|
||
else
|
||
return null;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note 发送短信(大于接口)
|
||
* @param integer $SmsTemplateCodeIndex 模板序号
|
||
* @param array $SmsTemplateParameter 短信参数
|
||
* @param string $Telphone 电话号码
|
||
* @return bool
|
||
*/
|
||
public function _SendSms($SmsTemplateCodeIndex, $SmsTemplateParameter, $Telphone)
|
||
{
|
||
$sms = new SmsDemo(self::SMS_ACCESSKEYID, self::SMS_ACCESSKEYSECRET, self::SMS_SIGNNAME);
|
||
$ret = $sms->SendSms($this->GetSmsTemplateCode($SmsTemplateCodeIndex), $Telphone, $SmsTemplateParameter);
|
||
|
||
if (strcasecmp($ret->Code, 'ok') == 0)
|
||
return null;
|
||
else
|
||
return $ret->Message;
|
||
}
|
||
|
||
|
||
/**
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $Request
|
||
* @param ReturnParameter $Return
|
||
* @return bool
|
||
*/
|
||
public function Send($Request, &$Return)
|
||
{
|
||
$SmsTemplateCodeIndex = $Request->biz_content['index']; /// 模板序号
|
||
$SmsTemplateParameter = $Request->biz_content['param']; /// 短信参数
|
||
$Telphone = $Request->biz_content['phone']; /// 电话号码
|
||
|
||
//$Result = $this->_SendMessage($SmsTemplateCodeIndex, $SmsTemplateParameter, $Telphone);
|
||
$Result = $this->_SendSms($SmsTemplateCodeIndex, $SmsTemplateParameter, $Telphone);
|
||
if (is_null($Result))
|
||
return true;
|
||
|
||
$Return->SetErrors(ERRORCODE_SMSSENDERROR, $Result);
|
||
return false;
|
||
}
|
||
|
||
|
||
/**
|
||
* 发送绑定短信验证码
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
* method=sms.sms.sendBindCode&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","phone":"18170825201"}
|
||
*/
|
||
public function sendBindCode($inParam, $outParam)
|
||
{
|
||
//$outParam->seterrors(ERRORCODE_DISABLED, ERRORINFO_DISABLED);
|
||
//return false;
|
||
|
||
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
|
||
|
||
if (!is_array($request_data))
|
||
{
|
||
/// 参数格式错误
|
||
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$agent_id = isset($request_data['agentid']) ? $request_data['agentid'] : '';
|
||
$channel_id = isset($request_data['channelid']) ? $request_data['channelid'] : '';
|
||
$sales_id = isset($request_data['salesid']) ? $request_data['salesid'] : ''; /// 代理号
|
||
$phone = isset($request_data['phone']) ? $request_data['phone'] : ''; /// 手机号
|
||
$is_bind = isset($request_data['isbind']) ? intval($request_data['isbind']) : 0; /// 是否绑定(0:解绑;1:绑定)
|
||
|
||
if (empty($agent_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
|
||
return false;
|
||
}
|
||
if (empty($channel_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
|
||
return false;
|
||
}
|
||
|
||
switch ($is_bind)
|
||
{
|
||
case 1: /// 解绑
|
||
if (empty($sales_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 判断代理是否存在
|
||
$salesInfo = $this->PDO_Request(/** @lang text */
|
||
'select idx, saus_tel, is_send_star from sales_user where saus_agentid=? and saus_channelid=? and saus_salesid=?',
|
||
$agent_id, $channel_id, $sales_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if (count($salesInfo) < 1)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
|
||
return false;
|
||
}
|
||
|
||
if ($salesInfo[0]['is_send_star'] != 1 || empty($salesInfo[0]['saus_tel']))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_NOBINDEDTELERROR, ERRORINFO_NOBINDEDTELERROR);
|
||
return false;
|
||
}
|
||
|
||
$phone = $salesInfo[0]['saus_tel'];
|
||
|
||
break;
|
||
|
||
case 0: /// 绑定
|
||
if (empty($phone))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TELERROR, ERRORINFO_TELERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 判断手机号码是否正确
|
||
if (!preg_match('/^1[3456789]{1}\d{9}$/', $phone))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TELERROR, ERRORINFO_TELERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 判断代理是否存在
|
||
$salesInfo = $this->PDO_Request(/** @lang text */
|
||
'select idx, saus_tel, is_send_star from sales_user where saus_agentid=? and saus_channelid=? and saus_salesid=?',
|
||
$agent_id, $channel_id, $sales_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if (count($salesInfo) < 1)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 该代理已绑定过手机并且手机号为同一个手机号
|
||
if ($salesInfo[0]['is_send_star'] == 1 && !empty($salesInfo[0]['saus_tel']) && $phone == $salesInfo[0]['saus_tel'])
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_BINDEDTELERROR, ERRORINFO_BINDEDTELERROR);
|
||
return false;
|
||
}
|
||
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
|
||
/// 生成随机码
|
||
$randCode = rand(100000, 999999);
|
||
/// 发送短信
|
||
$Result = $this->_SendSms(self::SMSINDEX_AUTHENTICATION, array('code' => $randCode, 'product' => '代理',), $phone);
|
||
if (!is_null($Result))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SMSSENDERROR, '短信发送太频繁,请稍候再试');
|
||
return false;
|
||
}
|
||
|
||
/// 记录数据库中
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
$ret = $this->PDO_Execute(/** @lang */
|
||
'update sales_sms_code set status=1 where status=0 and agent_id=? and channnel_id=? and phone=?', $agent_id, $channel_id, $phone);
|
||
if (!$ret || !$this->PDO_IsDone())
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$ret = $this->PDO_Execute(/** @lang */
|
||
'insert into sales_sms_code(agent_id, channnel_id, phone, code, status, is_bind, create_time) values(?, ?, ?, ?, 0, ?, now());',
|
||
$agent_id, $channel_id, $phone, $randCode, $is_bind);
|
||
|
||
if (!$ret || !$this->PDO_IsDone())
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$outParam->biz_content = array('code'=>$randCode);
|
||
|
||
$this->PDO_Commit();
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$this->PDO_Rollback();
|
||
$outParam->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 绑定手机送星星
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
* ?method=sms.sms.bindPhone&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","phone":"18170825201","salesid":203066,"msgcode":882940}
|
||
*/
|
||
public function bindPhone($inParam, $outParam)
|
||
{
|
||
/*$outParam->seterrors(ERRORCODE_DISABLED, ERRORINFO_DISABLED);
|
||
return false;*/
|
||
|
||
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
|
||
|
||
if (!is_array($request_data))
|
||
{
|
||
/// 参数格式错误
|
||
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$agent_id = isset($request_data['agentid']) ? $request_data['agentid'] : '';
|
||
$channel_id = isset($request_data['channelid']) ? $request_data['channelid'] : '';
|
||
$sales_id = isset($request_data['salesid']) ? $request_data['salesid'] : '';
|
||
$msg_code = isset($request_data['msgcode']) ? $request_data['msgcode'] : '';
|
||
$phone = isset($request_data['phone']) ? $request_data['phone'] : '';
|
||
|
||
if (empty($agent_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
|
||
return false;
|
||
}
|
||
if (empty($channel_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
|
||
return false;
|
||
}
|
||
if (empty($sales_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
|
||
return false;
|
||
}
|
||
if (strlen($msg_code) != 6)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_MSGLENGTHERROR, ERRORINFO_MSGLENGTHERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 判断代理是否存在
|
||
$command =/** @lang text */<<<EOL
|
||
select
|
||
idx, user_id, saus_tel, is_send_star, saus_nickname,
|
||
saus_avatar, saus_roomcard, saus_bean, player_id, diamond
|
||
from
|
||
sales_user
|
||
where
|
||
saus_agentid = ? and
|
||
saus_channelid = ? and
|
||
saus_salesid = ?
|
||
EOL;
|
||
$salesInfo = $this->PDO_Request($command, $agent_id, $channel_id, $sales_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
if (count($salesInfo) < 1)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
|
||
return false;
|
||
}
|
||
|
||
$player_id = $salesInfo[0]['player_id'];
|
||
|
||
if ($salesInfo[0]['is_send_star'] == 1 && !empty($salesInfo[0]['saus_tel']))
|
||
{
|
||
/// 已经绑定了手机,解绑
|
||
/// 判断短信验证码是否匹配
|
||
$dbMsgData = $this->PDO_Request(/** @lang text */
|
||
'select id, code from sales_sms_code where agent_id=? and channnel_id=? and phone=? and status=0',
|
||
$agent_id, $channel_id, $phone);
|
||
if (!is_array($dbMsgData) || count($dbMsgData) < 1)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_MSGNODATAERROR, ERRORINFO_MSGNODATAERROR);
|
||
return false;
|
||
}
|
||
|
||
if ($dbMsgData[0]['code'] != $msg_code)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TELMSGERROR, ERRORINFO_TELMSGERROR);
|
||
return false;
|
||
}
|
||
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
/// 如果存在账户信息,则需要修改账户信息
|
||
if (!empty($salesInfo[0]['user_id']))
|
||
{
|
||
$this->pdo_execute(/** @lang text */
|
||
'update ct_user_account set card = card - ?, currency = currency - ?, diamond = diamond - ? where user_id = ? and agent_id = ? and channel_id = ?',
|
||
$salesInfo[0]['saus_roomcard'], $salesInfo[0]['saus_bean'], $salesInfo[0]['diamond'], $salesInfo[0]['user_id'], $agent_id, $channel_id);
|
||
if (!$this->PDO_IsDone())
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
|
||
/// 修改代理信息表,把绑定信息置空
|
||
$ret = $this->PDO_Execute(/** @lang */
|
||
'update sales_user set saus_tel = null, user_id = null where idx = ?',
|
||
$salesInfo[0]['idx']);
|
||
if (!$ret || !$this->PDO_IsDone())
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 修改对应的校验码
|
||
$ret = $this->PDO_Execute(/** @lang */'update sales_sms_code set status = 1, sales_id = ? where id = ?', $sales_id, $dbMsgData[0]['id']);
|
||
if (!$ret || !$this->PDO_IsDone())
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$this->PDO_Commit();
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$this->PDO_Rollback();
|
||
$outParam->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
/// 未绑定手机,进行验证码验证和绑定
|
||
if (empty($phone))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TELERROR, ERRORINFO_TELERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 判断手机号码是否正确
|
||
if (!preg_match('/^1[3456789]{1}\d{9}$/', $phone))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TELERROR, ERRORINFO_TELERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 判断短信验证码是否匹配
|
||
$dbMsgData = $this->PDO_Request(/** @lang text */
|
||
'select id, code from sales_sms_code where agent_id=? and channnel_id=? and phone=? and status=0',
|
||
$agent_id, $channel_id, $phone);
|
||
|
||
if (!is_array($dbMsgData) || count($dbMsgData) < 1)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_MSGNODATAERROR, ERRORINFO_MSGNODATAERROR);
|
||
return false;
|
||
}
|
||
|
||
if ($dbMsgData[0]['code'] != $msg_code)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TELMSGERROR, ERRORINFO_TELMSGERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 获取代理绑定手机后赠送的星星数
|
||
$sendStarData = $this->PDO_Request(/** @lang text */
|
||
'select idx, send_star_num from agent_channel where agch_agentid=? and agch_channelid=?',
|
||
$agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
$sendStarNum = count($sendStarData) > 0 ? intval($sendStarData[0]['send_star_num']) : 0;
|
||
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
if (empty($salesInfo[0]['user_id']))
|
||
{
|
||
/// 判断是否存在该手机号对应的用户信息
|
||
$user_info = $this->pdo_request(/** @lang text */'select id from ct_user_info where phone = ?', $phone);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
if (empty($user_info))
|
||
{
|
||
/// 不存在则新增
|
||
$this->pdo_execute(/** @lang text */
|
||
'insert into ct_user_info(name,phone,avatar,create_time) values (?,?,?,unix_timestamp())',
|
||
$salesInfo[0]['saus_nickname'], $phone, $salesInfo[0]['saus_avatar']);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
$user_id = $this->PDO_LastInsertId();
|
||
}
|
||
else
|
||
$user_id = $user_info[0]['id'];
|
||
|
||
/// 判断该用户信息下,该渠道对应是否存在账户信息
|
||
$user_account = $this->pdo_request(/** @lang text */
|
||
'select 1 from ct_user_account where user_id = ? and agent_id = ? and channel_id = ?',
|
||
$user_id, $agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
if (empty($user_account)) /// 不存在则新增
|
||
$this->pdo_execute(/** @lang text */
|
||
'insert into ct_user_account(user_id, agent_id, channel_id, card, currency, diamond, enabled, create_time) values (?,?,?,?,?,?,1,unix_timestamp())',
|
||
$user_id, $agent_id, $channel_id, $salesInfo[0]['saus_roomcard'], $salesInfo[0]['saus_bean'], $salesInfo[0]['diamond']);
|
||
else /// 存在则修改账户余额
|
||
$this->pdo_execute(/** @lang text */
|
||
'update ct_user_account set enabled = 1, card = card + ?, currency = currency + ?, diamond = diamond + ? where user_id = ? and agent_id = ? and channel_id = ?',
|
||
$salesInfo[0]['saus_roomcard'], $salesInfo[0]['saus_bean'], $salesInfo[0]['diamond'], $user_id, $agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
}
|
||
else
|
||
$user_id = $salesInfo[0]['user_id'];
|
||
|
||
/// 查询已绑定到该手机的账号余额
|
||
$ret = $this->pdo_request(/** @lang text */
|
||
'select sum(saus_roomcard) card, sum(saus_bean) bean from sales_user where saus_agentid = ? and saus_channelid = ? and saus_tel = ?',
|
||
$agent_id, $channel_id, $phone
|
||
);
|
||
if (!$ret || !$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$card = intval(@$ret[0]['card']);
|
||
$bean = floatval(@$ret[0]['bean']);
|
||
$diamond = intval(@$ret[0]['diamond']);
|
||
|
||
/// 解绑以前绑定的账号
|
||
$command = /** @lang text */'select count(0) c from sales_user where saus_agentid = ? and saus_channelid = ? and saus_tel = ?';
|
||
$ret = $this->pdo_request($command, $agent_id, $channel_id, $phone);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
if (0 != intval($ret[0]['c'])) {
|
||
///=====================================================================================================================
|
||
/// 新增转卡记录
|
||
$command = /** @lang text */<<<EOL
|
||
insert into sales_transferbill(satr_agentid, channel_id, satr_openid, from_sales, satr_salesid, satr_amount, satr_transfertime)
|
||
select saus_agentid, saus_channelid, saus_openid, saus_salesid, ?, saus_roomcard, now()
|
||
from sales_user
|
||
where saus_agentid = ? and saus_channelid = ? and saus_tel = ? and saus_roomcard > 0
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $sales_id, $agent_id, $channel_id, $phone))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
/// 新增转星星记录
|
||
$command = /** @lang text */<<<EOL
|
||
insert into trans_star_record(agent_id, channel_id, union_id, open_id, send_id, get_id, type, amount, op_time)
|
||
select saus_agentid, saus_channelid, saus_unionid, saus_openid, saus_salesid, ?, 0, saus_bean, now()
|
||
from sales_user
|
||
where saus_agentid = ? and saus_channelid = ? and saus_tel = ? and saus_bean > 0
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $sales_id, $agent_id, $channel_id, $phone))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
/// 新增转移钻石的记录
|
||
$command = /** @lang text */<<<EOL
|
||
insert into trans_diamond_record(agent_id, channel_id, `from`, `to`, amount, oper_time)
|
||
select saus_agentid, saus_channelid, saus_salesid, ?, diamond, unix_timestamp()
|
||
from sales_user
|
||
where saus_agentid = ? and saus_channelid = ? and saus_tel = ? and diamond > 0
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $sales_id, $agent_id, $channel_id, $phone))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
/// 记录日志
|
||
$command = /** @lang text */<<<EOL
|
||
insert into ct_user_process_log(
|
||
from_agent, from_channel, from_user, to_agent, to_channel, to_user, oper_type, oper_data, remark, oper_time, is_process)
|
||
select
|
||
saus_agentid, saus_channelid, saus_salesid, ?, ?, ?, 112, concat('\{"from":"', ifnull(player_id, 0), '", "to":"{$player_id}"\}'), 'from_xxx为原代理信息,to_xxx为新代理信息, oper_data中from为源玩家编号,to为新玩家编号', unix_timestamp(), 0
|
||
from
|
||
sales_user
|
||
where
|
||
saus_agentid = ? and saus_channelid = ? and saus_tel = ? and is_send_star=1
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $agent_id, $channel_id, $sales_id, $agent_id, $channel_id, $phone))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
/// 迁移原账户的绑定关系
|
||
$command = /** @lang text */<<<EOL
|
||
update
|
||
sales_user
|
||
set
|
||
saus_parentid = ?
|
||
where
|
||
saus_parentid in
|
||
(
|
||
select
|
||
sales_id
|
||
from
|
||
(
|
||
select
|
||
saus_salesid sales_id
|
||
from
|
||
sales_user
|
||
where
|
||
saus_agentid = ? and saus_channelid = ? and saus_tel = ?
|
||
) t
|
||
)
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $sales_id, $agent_id, $channel_id, $phone))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
/// 清空原来绑定的代理账户并解绑
|
||
$command = /** @lang text */<<<EOL
|
||
update
|
||
player a,
|
||
sales_user b
|
||
set
|
||
a.phone = null
|
||
where
|
||
a.play_agentid = b.saus_agentid and
|
||
a.play_channelid = b.saus_channelid and
|
||
a.play_playerid = b.player_id and
|
||
b.saus_agentid = ? and
|
||
b.saus_channelid = ? and
|
||
b.saus_tel = ?
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $agent_id, $channel_id, $phone))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
$command = /** @lang text */'update sales_user set saus_roomcard = 0, saus_bean = 0, saus_tel = null, user_id = null where saus_agentid = ? and saus_channelid = ? and saus_tel = ?';
|
||
if (!$this->pdo_execute($command, $agent_id, $channel_id, $phone))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
}
|
||
|
||
/// 判断是否赠送过星星
|
||
if ($salesInfo[0]['is_send_star'] == 0)
|
||
$bean += $sendStarNum;
|
||
|
||
/// 绑定手机
|
||
$command = /** @lang text */<<<EOL
|
||
update
|
||
sales_user
|
||
set
|
||
saus_tel = ?,
|
||
is_send_star = 1,
|
||
saus_roomcard = saus_roomcard + ?,
|
||
saus_bean = saus_bean + ?,
|
||
diamond = diamond + ?,
|
||
user_id = ?,
|
||
saus_parentid =
|
||
(
|
||
select
|
||
saus_parentid
|
||
from
|
||
(
|
||
select
|
||
saus_parentid
|
||
from
|
||
sales_user
|
||
where
|
||
saus_salesid != saus_parentid and saus_agentid = ? and saus_channelid = ? and saus_tel = ?
|
||
) t
|
||
limit 1
|
||
)
|
||
where
|
||
idx = ?
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $phone, $card, $bean, $diamond, $user_id, $agent_id, $channel_id, $phone, $salesInfo[0]['idx']))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
/// 修改对应玩家信息
|
||
$command = /** @lang text */<<<EOL
|
||
update
|
||
player a,
|
||
sales_user b
|
||
set
|
||
a.phone = ?
|
||
where
|
||
a.play_agentid = b.saus_agentid and
|
||
a.play_channelid = b.saus_channelid and
|
||
a.play_playerid = b.player_id and
|
||
b.idx = ?
|
||
EOL;
|
||
if (!$this->pdo_execute($command, $phone, $salesInfo[0]['idx']))
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
///=====================================================================================================================
|
||
|
||
/// 修改赠送记录
|
||
$ret = $this->PDO_Execute(/** @lang text */'update sales_sms_code set status = 1, sales_id = ? where id=?', $sales_id, $dbMsgData[0]['id']);
|
||
if (!$ret || !$this->PDO_IsDone())
|
||
throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode());
|
||
|
||
$this->PDO_Commit();
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$this->PDO_Rollback();
|
||
$outParam->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 查询当前渠道下,指定手机绑定的账号列表
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
* ?method=sms.sms.bindPhone&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","phone":"18170825201","salesid":203066,"msgcode":882940}
|
||
*/
|
||
public function queryphone($request, $return)
|
||
{
|
||
$param = $request->biz_content;
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$agent_id = @$param['agentid'];
|
||
$channel_id = @$param['channleid'];
|
||
$phone = @$param['phone'];
|
||
|
||
if (empty($agent_id))
|
||
{
|
||
$return->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
|
||
return false;
|
||
}
|
||
if (empty($channel_id))
|
||
{
|
||
$return->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
|
||
return false;
|
||
}
|
||
/// 判断手机号码是否正确
|
||
if (!preg_match('/^1[3456789]{1}\d{9}$/', $phone))
|
||
{
|
||
$return->SetErrors(ERRORCODE_TELERROR, ERRORINFO_TELERROR);
|
||
return false;
|
||
}
|
||
|
||
$cmd = $this->NewServantCommand();
|
||
$ret = $cmd
|
||
->select('saus_salesid')
|
||
->from('sales_user')
|
||
->where(array('saus_agentid' => $agent_id, 'saus_channelid' => $channel_id, 'saus_tel' => $phone, 'is_send_star' => 1, ))
|
||
->request();
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->seterrors($this->geterrorcode(), $this->geterrorinfo());
|
||
return false;
|
||
}
|
||
|
||
$return->biz_content = array();
|
||
foreach($ret as $k => $v)
|
||
{
|
||
array_push($return->biz_content, $v);
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 查询当前渠道下,指定手机绑定的账号列表
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
* ?method=sms.sms.bindPhone&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","phone":"18170825201","salesid":203066,"msgcode":882940}
|
||
*/
|
||
public function send_sms($request, $return)
|
||
{
|
||
$param = $request->biz_content;
|
||
$id = $param['id'];
|
||
$code = rand(100000, 999999);
|
||
$return->biz_content = array('id'=>$id, 'code' => $code, );
|
||
return true;
|
||
}
|
||
} |