<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include_once dirname(__DIR__) . '/WeChatConfig/Config.php';
include_once dirname(__FILE__) . '/WxPayException.php';
include_once dirname(__FILE__) . '/WxPayRefund.php';
include_once dirname(__FILE__) . '/WxPayResults.php';
include_once dirname(__FILE__) . '/WxPayReport.php';
/**
* Description of WxPayApi
*
* @author Administrator
*/
class WxPayApi extends Config {
//put your code here
public function __construct() {
parent::__construct();
}
/**
*
* 统一下单,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayUnifiedOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function unifiedOrder($inputObj, $timeOut = 6) {
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//检测必填参数
if (!$inputObj->IsOut_trade_noSet()) {
throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
} else if (!$inputObj->IsBodySet()) {
throw new WxPayException("缺少统一支付接口必填参数body!");
} else if (!$inputObj->IsTotal_feeSet()) {
throw new WxPayException("缺少统一支付接口必填参数total_fee!");
} else if (!$inputObj->IsTrade_typeSet()) {
throw new WxPayException("缺少统一支付接口必填参数trade_type!");
}
//关联参数
if ($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()) {
throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
}
if ($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()) {
throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
}
$inputObj->SetSpbill_create_ip(self::get_client_ip()); //终端ip
//$inputObj->SetSpbill_create_ip("1.1.1.1");
$inputObj->SetNonce_str(self::getNonceStr()); //随机字符串
//签名https://cpro.baidu.com/cpro/ui/uijs.php?en=mywWUA71T1YsFh7sT7qGujYsFhPh5HcsFhPC5H0huAbqrauGTdq9TZ0qnauJp1Y1PWPbPjI9Pym1mWNBuym1Fh_qpgf-f1R-wH0-wjD-fWR-wjD-fHT-wj0-fHn-f1R-f1R-f1n-wbchp10qpgf-f1R-wH0-wjD-fWR-wjD-fHT-wj0-fHn-f1R-f1R-f1n-wbchp1DqFRfdFRfzTA9sFRc1FRPjFRfsFRmzFRfYFRckFh_z5iNDPBNaniNjwBNAfiNjwBNaPiNjwaNanzuon1dspZ0-fWb-fHf-fWn-fYn-fYD-fHm-fWf-wbf-wjn-wWmhp1fqTA9sFRfkFRDLFRPAFRcsFRfkFRDLFRcLFRfkFhkdpvbqniuVmLKV5HDzPjRLriuk5yGBPH7xmLKzFMFB5H0hTMnqniu1uyk_ugFxpyfqniu1pyfquWPBuycduWP9PHfLnvf1PBu1IA-b5HDkPiuY5gwsmvkGmvV-ujPxpAnhIAfqnW6vPWm3rauYUgnqnHf4PWmYrjfYriuYIHddnW6vPWm3raud5y9YIZ0-nYD-nbm-nbuLILT-nbNJmWRkFHF7UhNYFMmqniuG5HF-nWnzPyRk&c=news&fv=25&itm=0&kdi0=8&kdi1=8&kdi2=8&kdi3=8&kdi4=8&lukid=1&mscf=22&n=10&nttp=1&p=baidu&ssp2=1&tsf=dtp:1&u=%2Farticle%2F14244%2Ehtm&urlid=0&jincheng1=1
$inputObj->SetSign();
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond(); //请求开始时间
$response = self::postXmlCurl($xml, $url, false, $timeOut);
$result = WxPayResults::Init($response);
$result1 = json_encode($result);
self::reportCostTime($url, $startTimeStamp, $result); //上报请求花费时间
return $result;
}
/**
*
* 查询订单,WxPayOrderQuery中out_trade_no、transaction_id至少填一个
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayOrderQuery $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
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->SetNonce_str(self::getNonceStr()); //随机字符串
$inputObj->SetSign(); //签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond(); //请求开始时间
$response = self::postXmlCurl($xml, $url, false, $timeOut);
$result = WxPayResults::Init($response);
self::reportCostTime($url, $startTimeStamp, $result); //上报请求花费时间
return $result;
}
/**
*
* 关闭订单,WxPayCloseOrder中out_trade_no必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayCloseOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function closeOrder($inputObj, $timeOut = 6) {
$url = "https://api.mch.weixin.qq.com/pay/closeorder";
//检测必填参数
if (!$inputObj->IsOut_trade_noSet()) {
throw new WxPayException("订单查询接口中,out_trade_no必填!");
}
$inputObj->SetNonce_str(self::getNonceStr()); //随机字符串
$inputObj->SetSign(); //签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond(); //请求开始时间
$response = self::postXmlCurl($xml, $url, false, $timeOut);
$result = WxPayResults::Init($response);
self::reportCostTime($url, $startTimeStamp, $result); //上报请求花费时间
return $result;
}
/**
*
* 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
* out_refund_no、total_fee、refund_fee、op_user_id为必填参数
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayRefund $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function refund($inputObj, $timeOut = 6) {
$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至少填一个!");
// 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(); //签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond(); //请求开始时间
$response = self::postXmlCurl($xml, $url, true, $timeOut);
$result = WxPayResults::Init($response);
self::reportCostTime($url, $startTimeStamp, $result); //上报请求花费时间
return $result;
}
/**
*
* 查询退款
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
WeChatSDK.rar (11个子文件)
WeChatSDK
WeChatConfig
Config.php 2KB
WeChatSDK.php 9KB
WeChatData
WxPayUnifiedOrder.php 13KB
WxPayException.php 508B
WxPayApi.php 24KB
WxPayJsApiPay.php 4KB
WxPayReport.php 11KB
WxAppPayApi.php 5KB
WxPayRefund.php 8KB
WxPayDataBase.php 3KB
WxPayResults.php 2KB
共 11 条
- 1
资源评论
- liulf6421616792020-07-22东西不错;值得大家借鉴
紫云沫雪こ
- 粉丝: 47
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功