/** * * 生成直接支付url,支付url有效期为2小时,模式二 * @param WxPayUnifiedOrder $input */ public function GetPayUrl($input) { if ($input->GetTrade_type() == "NATIVE") { $result = WxPayApi::unifiedOrder($input); return $result; } }
public function Queryorder($transaction_id) { $input = new WxPayOrderQuery(); $input->SetTransaction_id($transaction_id); $result = WxPayApi::orderQuery($input); // Log::DEBUG("query:" . json_encode($result)); if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS") { return $result; } return false; }
/** * * 获取jsapi支付的参数 * @param array $UnifiedOrderResult 统一支付接口返回的数据 * @throws WxPayException * * @return json数据,可直接填入js函数作为参数 */ public function GetJsApiParameters($UnifiedOrderResult) { if (!array_key_exists("appid", $UnifiedOrderResult) || !array_key_exists("prepay_id", $UnifiedOrderResult) || $UnifiedOrderResult['prepay_id'] == "") { throw new WxPayException("参数错误"); } $jsapi = new WxPayJsApiPay(); $jsapi->SetAppid($UnifiedOrderResult["appid"]); $timeStamp = time(); $jsapi->SetTimeStamp("{$timeStamp}"); $jsapi->SetNonceStr(WxPayApi::getNonceStr()); $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']); $jsapi->SetSignType("MD5"); $jsapi->SetPaySign($jsapi->MakeSign()); $parameters = json_encode($jsapi->GetValues()); return $parameters; }
public function NotifyProcess($data, &$msg) { //echo "处理回调"; // Log::DEBUG("call back:" . json_encode($data)); if (!array_key_exists("openid", $data) || !array_key_exists("product_id", $data)) { $msg = "回调数据异常"; return false; } $openid = $data["openid"]; $product_id = $data["product_id"]; //统一下单 $result = $this->unifiedorder($openid, $product_id); if (!array_key_exists("appid", $result) || !array_key_exists("mch_id", $result) || !array_key_exists("prepay_id", $result)) { $msg = "统一下单失败"; return false; } $this->SetData("appid", $result["appid"]); $this->SetData("mch_id", $result["mch_id"]); $this->SetData("nonce_str", WxPayApi::getNonceStr()); $this->SetData("prepay_id", $result["prepay_id"]); $this->SetData("result_code", "SUCCESS"); $this->SetData("err_code_des", "OK"); return true; }
/** * * 撤销订单,如果失败会重复调用10次 * @param string $out_trade_no * @param 调用深度 $depth */ public function cancel($out_trade_no, $depth = 0) { if ($depth > 10) { return false; } $clostOrder = new WxPayReverse(); $clostOrder->SetOut_trade_no($out_trade_no); $result = WxPayApi::reverse($clostOrder); //接口调用失败 if ($result["return_code"] != "SUCCESS") { return false; } //如果结果为success且不需要重新调用撤销,则表示撤销成功 if ($result["result_code"] != "SUCCESS" && $result["recall"] == "N") { return true; } else { if ($result["recall"] == "Y") { return $this->cancel($out_trade_no, ++$depth); } } return false; }
/** * 下载对账单 * @throws WxPayException */ public function actionDownloadBill() { if (isset($_REQUEST["bill_date"]) && $_REQUEST["bill_date"] != "") { $bill_date = $_REQUEST["bill_date"]; $bill_type = $_REQUEST["bill_type"]; $input = new WxPayDownloadBill(); $input->SetBill_date($bill_date); $input->SetBill_type($bill_type); $file = WxPayApi::downloadBill($input); // TODO:: 对账单文件处理 exit(0); } }