示例#1
0
 /**
  * 
  *退款接口
  *
  */
 public static function refund($inputObj, $timeOut = 6, $f1, $f2, $key)
 {
     global $_W, $_GPC;
     $url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
     //检测必填参数
     if (!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
         throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
     } else {
         if (!$inputObj->IsOut_refund_noSet()) {
             throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
         } else {
             if (!$inputObj->IsTotal_feeSet()) {
                 throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
             } else {
                 if (!$inputObj->IsRefund_feeSet()) {
                     throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
                 } else {
                     if (!$inputObj->IsOp_user_idSet()) {
                         throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
                     }
                 }
             }
         }
     }
     $inputObj->SetNonce_str(self::getNonceStr());
     //随机字符串
     $inputObj->SetSign($key);
     //签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = self::getMillisecond();
     //请求开始时间
     $response = self::postXmlCurl($xml, $url, true, $timeOut, $f1, $f2);
     $result = WxPayResults::Init($response);
     return $result;
 }
示例#2
0
 public function verifyNotify()
 {
     $xml = file_get_contents('php://input', 'r');
     $re = WxPayResults::Init($xml);
     $this->log->INFO('RESULTS FROM XML:' . json_encode($re));
     if ($re['return_code'] == 'FAIL') {
         $this->log->ERROR($re['return_msg'] . '|' . $re['err_code_des']);
         throw new Exception("微信 preorder 错误-" . $re['return_msg'], 9001);
     }
     return $re;
 }
示例#3
0
 /**
  *
  * 验证微信签名
  */
 public static function checkSign()
 {
     //获取通知的数据
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     //如果返回成功则验证签名
     try {
         $result = WxPayResults::Init($xml);
     } catch (WxPayException $e) {
         return false;
     }
     return true;
 }
示例#4
0
 public static function orderQuery($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/pay/orderquery";
     //检测必填参数
     if (!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
         throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
     }
     $inputObj->SetAppid(WxPayAPPConfig::APPID);
     //公众账号ID
     $inputObj->SetMch_id(WxPayAPPConfig::MCHID);
     //商户号
     $inputObj->SetNonce_str(self::getNonceStr());
     //随机字符串
     $inputObj->SetAppSign();
     //签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = parent::getMillisecond();
     //请求开始时间
     $response = parent::postXmlCurl($xml, $url, false, $timeOut);
     $result = WxPayResults::Init($response);
     parent::reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }
示例#5
0
 /**
  *
  * 支付结果通用通知
  * @param function $callback
  * 直接回调函数使用方法: notify(you_function);
  * 回调类成员函数方法:notify(array($this, you_function));
  * $callback  原型为:function function_name($data){}
  */
 public static function notify($callback, &$msg)
 {
     //获取通知的数据
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     //如果返回成功则验证签名
     try {
         $result = WxPayResults::Init($xml);
     } catch (WxPayException $e) {
         $msg = $e->errorMessage();
         return false;
     }
     return call_user_func($callback, $result);
 }
示例#6
0
 /**
  * 
  * 支付结果通用通知
  * @param function $callback
  * 直接回调函数使用方法: notify(you_function);
  * 回调类成员函数方法:notify(array($this, you_function));
  * $callback  原型为:function function_name($data){}
  */
 public static function notify($callback, &$msg)
 {
     //获取通知的数据
     $xml = file_get_contents("php://input");
     //如果返回成功则验证签名
     try {
         $result = WxPayResults::Init($xml);
     } catch (WxPayException $e) {
         $msg = $e->errorMessage();
         return false;
     }
     return call_user_func($callback, $result);
 }
 public function weixin_balance()
 {
     App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php'));
     $notify = new PayNotifyCallBack();
     $res = $notify->Handle(false);
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $result = WxPayResults::Init($xml);
     $this->loadModel('PaymentApiLog');
     $out_trade_no = isset($result["out_trade_no"]) ? $result["out_trade_no"] : '';
     $out_trade_no_arr = split("_", $out_trade_no);
     $api_log_id = $out_trade_no_arr[0];
     $payment_api_log = $this->PaymentApiLog->find('first', array('conditions' => array('PaymentApiLog.id' => $api_log_id, 'is_paid' => '0')));
     if (!empty($payment_api_log)) {
         //充值支付
         $user_id = $payment_api_log['PaymentApiLog']['type_id'];
         $add_money = $payment_api_log['PaymentApiLog']['amount'];
         $user_Info = $this->User->find('first', array('conditions' => array('User.id' => $user_id)));
         if (!empty($user_Info)) {
             $user_money = $user_Info['User']['balance'];
             $user_money = $user_money + $add_money;
             $user_data['id'] = $user_id;
             $user_data['balance'] = $user_money;
             $this->User->save($user_data);
             $user_Info['User']['balance'] = $user_money;
             $_SESSION['User'] = $user_Info;
             $payment_api_log['PaymentApiLog']['is_paid'] = '1';
             $this->PaymentApiLog->save($payment_api_log);
             //添加资金日志
             $BalanceLog['UserBalanceLog']['user_id'] = $user_id;
             $BalanceLog['UserBalanceLog']['amount'] = $payment_api_log['PaymentApiLog']['amount'];
             $BalanceLog['UserBalanceLog']['admin_user'] = $user_Info['User']['balance'];
             $BalanceLog['UserBalanceLog']['admin_note'] = '';
             $BalanceLog['UserBalanceLog']['system_note'] = '用户余额:' . $user_data['balance'] . '元';
             $BalanceLog['UserBalanceLog']['log_type'] = 'B';
             $BalanceLog['UserBalanceLog']['type_id'] = $payment_api_log['PaymentApiLog']['id'];
             $BalanceLog['UserBalanceLog']['created'] = date('Y-m-d H:i:s', time());
             $this->UserBalanceLog->save($BalanceLog);
         }
     }
 }
 function isWeChatIPNValid($ipnXml)
 {
     //如果返回成功则验证签名
     try {
         $result = WxPayResults::Init($ipnXml);
         $this->ipn = $result;
     } catch (WxPayException $e) {
         $msg = $e->errorMessage();
         return false;
     }
     Log::DEBUG("call back  ipn:" . json_encode($result));
     if (!array_key_exists("transaction_id", $result)) {
         return false;
     }
     if (!$this->Queryorder($result["transaction_id"])) {
         return false;
     }
     return true;
 }
示例#9
0
 public function callBack()
 {
     $file = '/ding/protected/module/default/cache/callback-' . date("Y-m--d") . '.php';
     $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
     $result = WxPayResults::Init($xml);
     file_put_contents($file, var_export($result, true), FILE_APPEND);
     if ($result['result_code'] == 'SUCCESS') {
         $callBackOrderid = $result['out_trade_no'];
         $orderStatus = $result['result_code'];
         $order = DBproxy::getProcedure('Manage')->setDimension(2)->orderUp($orderStatus, 0, $callBackOrderid);
         if ($order['status'] == 0) {
             echo 'SUCCESS';
         }
     }
 }