Exemple #1
0
 public function createTransOrderForBatch($fields)
 {
     $longId = CommonUtil::longId();
     //$batchNo = $longId . sprintf('%03s', $fields['channel']) . sprintf('%02s', $fields['gateway']) . mt_rand(100, 999) ;
     $batchNo = date('ymdHis') . mt_rand(100, 999);
     $requestData = json_decode($fields['request_data'], true);
     foreach ($requestData as $field) {
         if (!in_array($fields['gateway'], $this->_allowTransGateway)) {
             throw new PayException(ErrorCode::ERR_GATEWAY_FAIL, '该gateway不允许提现');
         }
         $validation = new TransValidator($field);
         if (!$validation->passes(TransValidator::$transDetailRule)) {
             throw new PayException(ErrCode::ERR_PARAM, $validation->errors);
         }
         if ($fields['gateway'] == PayVars::GATEWAY_YEEPAY) {
             if (!isset($field['bank_code']) || !isset(PayBankVars::$yeepayBankAlis[$field['bank_code']])) {
                 throw new PayException(ErrCode::ERR_PARAM, '银行编码错误!');
             }
         }
         $account = AccountBiz::getInstance()->getOrCreateAccount($field['user_id'], $fields['channel']);
         $primaryId = CommonUtil::LongIdIncrease($longId);
         $merTransNo = $primaryId;
         $insertArr[] = ['id' => $primaryId, 'user_id' => $field['user_id'], 'account_id' => $account['id'], 'mer_trans_no' => null !== ($localEnv = \GlobalConfig::getLocalEnv()) ? $merTransNo . $localEnv : $merTransNo, 'batch_no' => $batchNo, 'trans_amount' => $field['trans_amount'], 'create_time' => time(), 'person_name' => $field['user_name'], 'person_account' => $field['user_account'], 'channel' => $fields['channel'], 'gateway' => $fields['gateway'], 'callback_url' => $fields['callback_url'], 'subject' => $fields['subject'], 'body' => isset($field['body']) ? $field['body'] : '', 'mobile_no' => isset($field['mobile']) ? $field['mobile'] : '', 'bank_code' => isset($field['bank_code']) ? $field['bank_code'] : '', 'busi_trans_no' => isset($field['busi_trans_no']) ? $field['busi_trans_no'] : ''];
     }
     $trans = new TransModel();
     if (true !== $trans->insert($insertArr)) {
         throw new PayException(ErrCode::ERR_SYSTEM, '数据库保存失败');
     }
     return $batchNo;
 }
 public function transQuery($order)
 {
     $config = $this->getConfig($order);
     $parameter = ['cmd' => 'BatchDetailQuery', 'mer_Id' => $config['partner'], 'batch_No' => $order['batch_no'], 'order_Id' => $order['mer_tran_no'], 'page_No' => 1];
     $parameter['hmac'] = $yeeServer->hMac($parameter);
     $parameter['version'] = '1.0';
     $parameter['group_Id'] = $config['partner'];
     $parameter['query_Mode'] = 1;
     $resultXml = $yeeServer->sendRequest($parameter);
     $result = CommonUtil::xmlToArray($resultXml);
     $notice['type'] = 'trans';
     $notice['details'] = [];
     if (is_array($result)) {
         if ($result['ret_Code'] == 1) {
             foreach ($result['list'] as $item) {
                 $notice['details'][] = ['seller_partner' => $item['mer_id'], 'batch_no' => $result['batch_No'], 'mer_trans_no' => $item['order_Id'], 'user_account' => $item['payee_Bank_Account'], 'user_name' => $item['payee_Name'], 'trans_amount' => $item['real_pay_amount'], 'notify_status' => $item['bank_Status'] == 'S' ? 2 : 3, 'notify_log' => !empty($item['fail_Desc']) ? $item['fail_Desc'] : 'Success', 'ser_trans_no' => '', 'notify_time' => time(), 'pay_time' => strtotime($item['complete_Date'])];
             }
         }
     }
     return $notice;
 }
 public function notify($channel)
 {
     $xml = file_get_contents("php://input");
     //$xml = '<xml><appid><![CDATA[wx62ad814ba9bf0b68]]></appid>
     //    <bank_type><![CDATA[CFT]]></bank_type>
     //    <cash_fee><![CDATA[1]]></cash_fee>
     //    <fee_type><![CDATA[CNY]]></fee_type>
     //    <is_subscribe><![CDATA[Y]]></is_subscribe>
     //    <mch_id><![CDATA[1227304102]]></mch_id>
     //    <nonce_str><![CDATA[yj1vuhafyyuvmcpz2p9992a91ul06edd]]></nonce_str>
     //    <openid><![CDATA[oFA64s5NHmfwEaEl5jIfjTgsy1Pw]]></openid>
     //    <out_trade_no><![CDATA[test0702152451350439000000000095]]></out_trade_no>
     //    <result_code><![CDATA[SUCCESS]]></result_code>
     //    <return_code><![CDATA[SUCCESS]]></return_code>
     //    <sign><![CDATA[4E0910D81068E34969D263BE21A7BF99]]></sign>
     //    <time_end><![CDATA[20150702152605]]></time_end>
     //    <total_fee>1</total_fee>
     //    <trade_type><![CDATA[JSAPI]]></trade_type>
     //    <transaction_id><![CDATA[1008410170201507020336471776]]></transaction_id>
     //    </xml>' ;
     $params = CommonUtil::xmlToArray($xml);
     $partner = $params['mch_id'];
     $config = $this->getConfigByPartner($channel, $partner);
     $notify = new \Notify_pub($config);
     $notify->saveData($xml);
     $notice = [];
     if ($notify->checkSign() == TRUE) {
         /// 通信出错
         if ($notify->data["return_code"] == "FAIL") {
             $notify->setReturnParameter("return_code", "FAIL");
             //返回状态码
             $notify->setReturnParameter("return_msg", "通信出错");
             //返回信息
             /// 业务出错
         } elseif ($notify->data["result_code"] == "FAIL") {
             $notify->setReturnParameter("return_code", "FAIL");
             //返回状态码
             $notify->setReturnParameter("return_msg", "业务出错");
             //返回信息
             /// 支付成功
         } else {
             $notify->setReturnParameter("return_code", "SUCCESS");
             //设置返回码
             $notice['type'] = 'direct';
             $notice['mer_recharge_no'] = $params['out_trade_no'];
             //商户订单号
             $notice['ser_recharge_no'] = $params['transaction_id'];
             //第三方支付单号
             $notice['gateway_account'] = $params['openid'];
             //用户在商户appid下的唯一标识
             $notice['seller_partner'] = $params['mch_id'];
             //商户号
             $notice['notify_status'] = 2;
             $notice['notify_log'] = '支付成功';
             $notice['pay_time'] = strtotime($params['time_end']);
             $notice['notify_time'] = strtotime($params['time_end']);
             $notice['amount'] = $params['total_fee'];
             //订单金额
             $notice['bank_id'] = $params['bank_type'];
             //银行类型
             //$notice['attach']           = $params['attach'] ;           //商家数据包
         }
     } else {
         $notify->setReturnParameter("return_code", "FAIL");
         //返回状态码
         $notify->setReturnParameter("return_msg", "签名错误");
         //返回信息
     }
     $notice['output'] = $notify->returnXml();
     //给第三方显示
     return $notice;
 }