/** * 提交被扫支付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; }
/** * 提交被扫支付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; }