/**
  * Returns a singleton instance
  *
  * @access public
  */
 public static function &getInstance($config)
 {
     if (!isset(self::$_instances[0]) || !self::$_instances[0]) {
         self::$_instances[0] = MQClient::factory($config);
     }
     return self::$_instances[0];
 }
 /**
  * function description
  *
  * @param
  * @return void
  */
 public function execute($request)
 {
     header("Content-type:text/html;charset=utf-8");
     if ($request->format == 'json') {
         if (isset($_POST["_huitong_user"])) {
             $cookie_user = urldecode($_POST['_huitong_user']);
             $user = Sp_Account_User::parseStored($cookie_user);
             $activeId = $request->activeId;
             if (!is_numeric($user['id']) || $user['id'] < 1 || !is_numeric($activeId) || $activeId < 1) {
                 $jsonParam = array('code' => '500', 'message' => '上传错误');
                 echo json_encode($jsonParam);
                 exit;
             }
             $arrary = array();
             $up = new Util_Upload(array('savepath' => UPLOAD_ROOT . 'attendee', 'subdirpattern' => 'Y/m/d', 'israndname' => true, 'allowtype' => array('xls', 'xlsx'), 'maxsize' => 5120000));
             $up->uploadFile('file');
             // input's name property
             $msg = $up->getErrorMsg();
             $jsonParam = array();
             if (empty($msg)) {
                 $filename = $up->getUploadFileName();
                 if (is_readable($filename) == false) {
                     $jsonParam = array('code' => '500', 'message' => '文件不可读');
                     echo json_encode($jsonParam);
                     exit;
                 }
                 @chmod($filename, 0777);
                 $data = array('userId' => $user['id'], 'fileDir' => $filename);
                 $data['activeId'] = $activeId;
                 $lastid = Sp_Account_Attendee::uploadLog($data);
                 if ($lastid) {
                     if (class_exists('GearmanClient')) {
                         $client_active = MQClient::factory('participants');
                         $client_active->send('importParticipants', $data, false);
                     }
                 }
                 $jsonParam = array('code' => '200', 'message' => 'ok', 'url' => '', 'time' => time());
             } else {
                 $jsonParam = array('code' => '500', 'message' => $msg);
             }
             echo json_encode($jsonParam);
         } else {
             $jsonParam = array('code' => '500', 'message' => '错误访问');
             echo json_encode($jsonParam);
         }
     }
 }
 /**
  * 支付完成后返回处理
  * 
  * @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('zeningli@qq.com', '资金流处理失败!', $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('zeningli@qq.com', '资金流处理失败!', $body);
                         }
                     }
                 }
             }
         }
     } else {
         $body = print_r($_REQUEST, true);
         Sp_Admin_Mail::send('zeningli@qq.com', '易宝支付失败(签名验证失败)', $body);
         $view->assign('error_message', "抱歉,您的支付没有成功,请重新支付,谢谢");
         $view->out_404();
         return;
     }
 }
 /**
  * 发送函数(gearman's client)
  *
  * @param string $file
  * @param string $name
  * @param array $option empty
  * @return string
  */
 public static function add($section, $content)
 {
     extract($content, EXTR_SKIP);
     if ($user_id) {
         $user_id = explode(' ', $user_id);
     } else {
         $user_id = array();
     }
     if ($admin_id) {
         $admin_id = explode(' ', $admin_id);
     } else {
         $admin_id = array();
     }
     $MQClient = MQClient::factory('client_message');
     $MQlog = $MQClient->getLog();
     foreach ($user_id as $user) {
         $types = self::setting($section);
         if (is_array($types)) {
             if ($types['ischeckuser']) {
                 self::filtUserSet($user_id, $section, $types);
             }
             if (is_array($types)) {
                 foreach ($types as $v) {
                     $data = array('type' => $v, 'user_id' => $user, 'data' => $content);
                     $MQlog->log('会员消息发送 content = ' . json_encode($data));
                     $result = $MQClient->send("message_send", $data);
                 }
             }
         }
     }
     /*foreach($admin_id as $admin) {
     			$types = self::setting($section, '', $admin);
     			if(is_array($types)) {
     				foreach($types as $v) {
     					$data = array('type'=>$v, 'admin_id'=>$admin, 'data'=>$content);
     					$MQlog->log('管理后台消息发送 content = '.json_encode($data));
     					$result = $MQClient->send("message_send", $data);
     				}
     			}
     		}*/
 }
<?php

define("WORKER_PDO_TEST", 1);
/*
 * author zhaoyu
 * date 2015/04/10
 * 响应worker
 */
define('ROOT_PATH', __DIR__ . '/../../');
include_once ROOT_PATH . 'config/init.php';
$client_active = MQClient::factory('participants');
$client_active->send('importParticipants', array("uid" => 10086));
 /**
  * 支付完成后返回处理(异步)
  * 
  * @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('274211178@qq.com', '国付宝支付失败(数据库处理失败)', $body);
                 }
             }
         } else {
             $body = print_r($_REQUEST, true);
             Sp_Admin_Mail::send('274211178@qq.com', '国付宝支付失败(国付宝处理失败)', $body);
             echo 'RespCode=9999|JumpURL=';
         }
     } else {
         $body = print_r($_REQUEST, true);
         Sp_Admin_Mail::send('274211178@qq.com', '国付宝支付失败(签名验证失败)', $body);
         echo 'RespCode=9999|JumpURL=';
         exit;
     }
 }