/**
  * 支付完成后返回处理
  * 
  * @param array params
  * @return void
  */
 public function complete($params)
 {
     $view = new Sp_View();
     #	解析返回参数.
     $return = Sp_Payment_Yeepay_Common::getCallBackValue($r0_Cmd, $r1_Code, $r2_TrxId, $r3_Amt, $r4_Cur, $r5_Pid, $r6_Order, $r7_Uid, $r8_MP, $r9_BType, $hmac);
     #	判断返回签名是否正确(True/False)
     $bRet = Sp_Payment_Yeepay_Common::CheckHmac($r0_Cmd, $r1_Code, $r2_TrxId, $r3_Amt, $r4_Cur, $r5_Pid, $r6_Order, $r7_Uid, $r8_MP, $r9_BType, $hmac);
     #	以上代码和变量不需要修改.
     #	校验码正确.
     if ($bRet) {
         if ($r1_Code == "1") {
             #	需要比较返回的金额与商家数据库中订单的金额是否相等,只有相等的情况下才认为是交易成功.
             #	并且需要对返回的处理进行事务控制,进行记录的排它性处理,在接收到支付结果通知后,判断是否进行过业务逻辑处理,不要重复进行业务逻辑处理,防止对同一条交易重复发货的情况发生.
             $user_id = $r8_MP;
             //用户id
             $sn = trim($r6_Order);
             //订单号
             $amount = floatval($r3_Amt);
             //金额
             $recharge_info = Sp_Trade_Recharge::getBySn($sn);
             if (floatval($recharge_info['amount']) == $amount and $recharge_info['user_id'] == $user_id) {
                 if ($r9_BType == "1") {
                     #交易成功 在线支付页面返回
                     $request = Request::current();
                     if ($request->isMobile()) {
                         Loader::redirect(SP_URL_WAP . 'moneyrecord.html');
                     } else {
                         Loader::redirect(SP_URL_USER . 'moneyrecord.html');
                     }
                     /*
                     						$ret = false;
                     						if($recharge_info['status'] < 1) {
                     							$param = array(
                     								'id' => $recharge_info['id'],
                     								'user_id' => $user_id,
                     								'sn' => $sn,
                     								'amount' => $amount,
                     								'bank_sn' => $_REQUEST['ro_BankOrderId'],
                     								'trd_sn' => $_REQUEST['r2_TrxId'],
                     								'remark' => json_encode($_REQUEST)
                     							);
                     							$ret = Sp_Trade_Tradeprocess::recharge($param);
                     						}
                     						if($ret) {//处理成功
                     							$user = Sp_Account_User::getUserBase($user_id); //用户信息
                     							$data = array(
                     								'user_id' => $user_id,
                     								'account' => $amount,
                     								'user_name' => $user->data["username"],
                     								'email' => $user->data['email'],
                     								'realname' => $user->data["username"],
                     								'phone' => $user->data['phone'],
                     							);
                     							Sp_Message::send('recharge', $data);//发送消息
                     							Loader::redirect(SP_URL_USER.'moneyrecord.html');
                     						}elseif($recharge_info['status'] < 1) {//失败
                     							echo '资金流处理失败!';
                     							$body = print_r($_REQUEST,true);
                     							Sp_Admin_Mail::send('*****@*****.**', '资金流处理失败!', $body);
                     						}else{
                     							$request = Request::current();
                     							if($request->isMobile()) {
                     								Loader::redirect(SP_URL_WAP.'moneyrecord.html');
                     							}else{
                     								Loader::redirect(SP_URL_USER.'moneyrecord.html');
                     							}
                     						}*/
                 } elseif ($r9_BType == "2") {
                     #如果需要应答机制则必须回写流,以success开头,大小写不敏感.
                     $ret = false;
                     if ($recharge_info['status'] == 1) {
                         echo "success";
                     } elseif ($recharge_info['status'] < 1) {
                         $param = array('id' => $recharge_info['id'], 'user_id' => $user_id, 'sn' => $sn, 'amount' => $amount, 'bank_sn' => $_REQUEST['ro_BankOrderId'], 'trd_sn' => $_REQUEST['r2_TrxId'], 'remark' => json_encode($_REQUEST));
                         $amount_num = Sp_Trade_Recharge::getUserRechargeReport('WHERE status = 1 AND user_id=' . $user_id);
                         $ret = Sp_Trade_Tradeprocess::recharge($param);
                         if ($ret) {
                             //处理成功
                             //首冲奖励
                             if ($amount_num == 0) {
                                 $active_send_info = array('uid' => $user_id, 'type' => 'first_recharge');
                                 $client_active = MQClient::factory('active');
                                 $client_active->send('activePrizeReset_new_register', $active_send_info);
                             }
                             $user = Sp_Account_User::getUserBase($user_id);
                             //用户信息
                             $data = array('user_id' => $user_id, 'account' => $amount, 'user_name' => $user->data["username"], 'email' => $user->data['email'], 'realname' => $user->data["username"], 'phone' => $user->data['phone']);
                             Sp_Message::send('recharge', $data);
                             //发送消息
                         } else {
                             echo '资金流处理失败!';
                             $body = print_r($_REQUEST, true);
                             Sp_Admin_Mail::send('*****@*****.**', '资金流处理失败!', $body);
                         }
                     }
                 }
             }
         }
     } else {
         $body = print_r($_REQUEST, true);
         Sp_Admin_Mail::send('*****@*****.**', '易宝支付失败(签名验证失败)', $body);
         $view->assign('error_message', "抱歉,您的支付没有成功,请重新支付,谢谢");
         $view->out_404();
         return;
     }
 }
 /**
  * 支付完成后返回处理(异步)
  * 
  * @param array params
  * @return void
  */
 public function notify($params)
 {
     $view = new Sp_View();
     #	解析返回参数.
     $version = $params["version"];
     $charset = $params["charset"];
     $language = $params["language"];
     $signType = $params["signType"];
     $tranCode = $params["tranCode"];
     $merchantID = $params["merchantID"];
     $merOrderNum = $params["merOrderNum"];
     $tranAmt = $params["tranAmt"];
     $feeAmt = $params["feeAmt"];
     $frontMerUrl = $params["frontMerUrl"];
     $backgroundMerUrl = $params["backgroundMerUrl"];
     $tranDateTime = $params["tranDateTime"];
     $tranIP = $params["tranIP"];
     $respCode = $params["respCode"];
     $msgExt = $params["msgExt"];
     $orderId = $params["orderId"];
     $gopayOutOrderId = $params["gopayOutOrderId"];
     $bankCode = $params["bankCode"];
     $tranFinishTime = $params["tranFinishTime"];
     $merRemark1 = $params["merRemark1"];
     $merRemark2 = $params["merRemark2"];
     $signValue = $params["signValue"];
     #	判断返回签名是否正确(True/False)
     $bRet = Sp_Payment_Gopay_HttpClient::CheckHmac($version, $tranCode, $merchantID, $merOrderNum, $tranAmt, $feeAmt, $tranDateTime, $frontMerUrl, $backgroundMerUrl, $orderId, $gopayOutOrderId, $tranIP, $respCode, '', self::$verficationCode, $signValue);
     if ($bRet) {
         if ($respCode == '0000') {
             $sn = trim($merOrderNum);
             //订单号
             $amount = floatval($tranAmt);
             //金额
             $recharge_info = Sp_Trade_Recharge::getBySn($sn);
             $amount_num = 1;
             if (floatval($recharge_info['amount']) == $amount) {
                 $ret = false;
                 if ($recharge_info['status'] == 1) {
                     $request = Request::current();
                     if ($request->isMobile()) {
                         echo 'RespCode=0000|JumpURL=' . SP_URL_WAP . 'moneyrecord.html';
                     } else {
                         echo 'RespCode=0000|JumpURL=' . SP_URL_USER . 'moneyrecord.html';
                     }
                     exit;
                 } elseif ($recharge_info['status'] < 1) {
                     $amount_num = Sp_Trade_Recharge::getUserRechargeReport('WHERE status = 1 AND user_id=' . $recharge_info['user_id']);
                     $param = array('id' => $recharge_info['id'], 'user_id' => $recharge_info['user_id'], 'sn' => $sn, 'amount' => $amount, 'bank_sn' => $_REQUEST['gopayOutOrderId'], 'trd_sn' => $_REQUEST['orderId'], 'remark' => json_encode($_REQUEST));
                     $ret = Sp_Trade_Tradeprocess::recharge($param);
                 }
                 if ($ret) {
                     //处理成功
                     //首冲奖励
                     if ($amount_num == 0) {
                         $active_send_info = array('uid' => $recharge_info['user_id'], 'type' => 'first_recharge');
                         $client_active = MQClient::factory('active');
                         $client_active->send('activePrizeReset_new_register', $active_send_info);
                     }
                     $user = Sp_Account_User::getUserBase($recharge_info['user_id']);
                     //用户信息
                     $data = array('user_id' => $recharge_info['user_id'], 'account' => $amount, 'user_name' => $user->data["username"], 'email' => $user->data['email'], 'realname' => $user->data["username"], 'phone' => $user->data['phone']);
                     Sp_Message::send('recharge', $data);
                     //发送消息
                     $request = Request::current();
                     if ($request->isMobile()) {
                         echo 'RespCode=0000|JumpURL=' . SP_URL_WAP . 'moneyrecord.html';
                     } else {
                         echo 'RespCode=0000|JumpURL=' . SP_URL_USER . 'moneyrecord.html';
                     }
                 } else {
                     echo 'RespCode=9999|JumpURL=';
                     $body = print_r($_REQUEST, true);
                     Sp_Admin_Mail::send('*****@*****.**', '国付宝支付失败(数据库处理失败)', $body);
                 }
             }
         } else {
             $body = print_r($_REQUEST, true);
             Sp_Admin_Mail::send('*****@*****.**', '国付宝支付失败(国付宝处理失败)', $body);
             echo 'RespCode=9999|JumpURL=';
         }
     } else {
         $body = print_r($_REQUEST, true);
         Sp_Admin_Mail::send('*****@*****.**', '国付宝支付失败(签名验证失败)', $body);
         echo 'RespCode=9999|JumpURL=';
         exit;
     }
 }