Exemplo n.º 1
0
 /**
  * 
  * 提交刷卡支付,并且确认结果,接口比较慢
  * @param WxPayMicroPay $microPayInput
  * @throws WxpayException
  * @return 返回查询接口的结果
  */
 public function pay($microPayInput)
 {
     //①、提交被扫支付
     $microPayInput->setWxPayApi($this->wxPayApi);
     $result = $this->wxPayApi->micropay($microPayInput, $this->wxPayConfig['CURL_TIMEOUT']);
     //如果返回成功
     /*		if(!array_key_exists("return_code", $result)
     			|| !array_key_exists("out_trade_no", $result)
     			|| !array_key_exists("result_code", $result))*/
     if (!array_key_exists("return_code", $result) || !array_key_exists("result_code", $result)) {
         throw new \WxPayException("interface_get_failure");
     }
     //签名验证
     $out_trade_no = $microPayInput->GetOut_trade_no();
     //②、接口调用成功,明确返回调用失败
     if ($result["return_code"] == "SUCCESS" && $result["result_code"] == "FAIL" && $result["err_code"] != "USERPAYING" && $result["err_code"] != "SYSTEMERROR") {
         throw new \WxPayException($result['err_code']);
         //			return false;
     }
     //③、确认支付是否成功
     $queryTimes = 6;
     while ($queryTimes > 0) {
         $succResult = 0;
         $queryResult = $this->query($out_trade_no, $succResult);
         //如果需要等待1s后继续
         if ($succResult == 2) {
             sleep(2);
             $queryTimes--;
             continue;
         } else {
             if ($succResult == 1) {
                 //查询成功
                 return $queryResult;
             } else {
                 //订单交易失败
                 return false;
             }
         }
     }
     //④、次确认失败,则撤销订单
     if (!$this->cancel($out_trade_no)) {
         throw new \WxpayException("cancel_order_failure");
     }
     throw new \Exception("wait_pay_time_out");
     //		return false;
 }
Exemplo n.º 2
0
require_once "../lib/WxPay.Api.php";
require_once "WxPay.MicroPay.php";
require_once 'log.php';
//初始化日志
$logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
$log = Log::Init($logHandler, 15);
//打印输出数组信息
function printf_info($data)
{
    foreach ($data as $key => $value) {
        echo "<font color='#00ff55;'>{$key}</font> : {$value} <br/>";
    }
}
if (isset($_REQUEST["auth_code"]) && $_REQUEST["auth_code"] != "") {
    $auth_code = $_REQUEST["auth_code"];
    $input = new WxPayMicroPay();
    $input->SetAuth_code($auth_code);
    $input->SetBody("刷卡测试样例-支付");
    $input->SetTotal_fee("1");
    $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
    $microPay = new MicroPay();
    printf_info($microPay->pay($input));
}
/**
 * 注意:
 * 1、提交被扫之后,返回系统繁忙、用户输入密码等错误信息时需要循环查单以确定是否支付成功
 * 2、多次(一半10次)确认都未明确成功时需要调用撤单接口撤单,防止用户重复支付
 */
?>
<body>  
	<form action="#" method="post">
Exemplo n.º 3
0
 /**
  * 提交被扫支付API
  * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
  * 由商户收银台或者商户后台调用该接口发起支付。
  * WxPayWxPayMicroPay中body、out_trade_no、total_fee、auth_code参数必填
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  *
  * @param WxPayMicroPay $inputObj
  * @param int $timeOut
  */
 public static function micropay($inputObj, $timeOut = 30)
 {
     $url = "https://api.mch.weixin.qq.com/pay/micropay";
     // 检测必填参数
     if (!$inputObj->IsBodySet()) {
         throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
     } elseif (!$inputObj->IsOut_trade_noSet()) {
         throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
     } elseif (!$inputObj->IsTotal_feeSet()) {
         throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
     } elseif (!$inputObj->IsAuth_codeSet()) {
         throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
     }
     $inputObj->SetSign();
     // 签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = self::getMillisecond();
     // 请求开始时间
     $response = self::postXmlCurl($xml, $url, false, $timeOut);
     $result = WxPayResults::Init($response, $inputObj->wx_config);
     self::reportCostTime($url, $startTimeStamp, $result);
     // 上报请求花费时间
     return $result;
 }
Exemplo n.º 4
0
 /**
  * 提交被扫支付API
  * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
  * 由商户收银台或者商户后台调用该接口发起支付。
  * WxPayWxPayMicroPay中body、out_trade_no、total_fee、auth_code参数必填
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayMicroPay $inputObj
  * @param int $timeOut
  * @return array
  * @throws WxPayException
  */
 public function micropay($inputObj, $timeOut = 10)
 {
     $url = "https://api.mch.weixin.qq.com/pay/micropay";
     //检测必填参数
     if (!$inputObj->IsBodySet()) {
         throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
     } else {
         if (!$inputObj->IsOut_trade_noSet()) {
             throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
         } else {
             if (!$inputObj->IsTotal_feeSet()) {
                 throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
             } else {
                 if (!$inputObj->IsAuth_codeSet()) {
                     throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
                 }
             }
         }
     }
     $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);
     //终端ip
     $inputObj->SetAppid($this->config->getAppId());
     //公众账号ID
     $inputObj->SetMch_id($this->config->getMchId());
     //商户号
     $inputObj->SetNonce_str($this->getNonceStr());
     //随机字符串
     $inputObj->SetSign();
     //签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = $this->getMillisecond();
     //请求开始时间
     $response = $this->postXmlCurl($xml, $url, false, $timeOut);
     $result = WxPayResults::Init($response);
     $this->reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }