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 */<<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 */<< 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 */<< 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 */<< 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 */<<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 */<<pdo_execute($command, $sales_id, $agent_id, $channel_id, $phone)) throw new Exception($this->GetErrorInfo() . '(' . __LINE__ . ')', $this->GetErrorCode()); /// 清空原来绑定的代理账户并解绑 $command = /** @lang text */<<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 */<<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 */<<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; } }