<?php
namespace tencent\wxpay;
use tencent\wxpay\base\WxPayNotifyResults;
use tencent\wxpay\base\WxPayReport;
use tencent\wxpay\base\WxPayResults;
/**
*
* 接口访问类,包含所有微信支付API列表的封装,类中方法为static方法,
* 每个接口有默认超时时间(除提交被扫支付为10s,上报超时时间为1s外,其他均为6s)
* @author widyhu
*
*/
class WxPayApi
{
/**
* SDK版本号
* @var string
*/
public static $VERSION = "3.0.10";
/**
*
* 统一下单,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayUnifiedOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function unifiedOrder($config, $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为必填参数!");
}
//异步通知url未设置,则使用配置文件中的url
if(!$inputObj->IsNotify_urlSet() && $config->GetNotifyUrl() != ""){
$inputObj->SetNotify_url($config->GetNotifyUrl());//异步通知url
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
//签名
$inputObj->SetSign($config);
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 查询订单,WxPayOrderQuery中out_trade_no、transaction_id至少填一个
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayOrderQuery $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function orderQuery($config, $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($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 关闭订单,WxPayCloseOrder中out_trade_no必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayCloseOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function closeOrder($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/closeorder";
//检测必填参数
if(!$inputObj->IsOut_trade_noSet()) {
throw new WxPayException("订单查询接口中,out_trade_no必填!");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $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 WxPayConfigInterface $config 配置对象
* @param WxPayRefund $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function refund($config, $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至少填一个!");
}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->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, true, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 查询退款
* 提交退款申请后,通过�
没有合适的资源?快使用搜索试试~ 我知道了~
微信的一些接口资源包(PHP),个人经过转码,只适合放在thinkPHP的拓展目录中
共33个文件
php:33个
需积分: 2 1 下载量 138 浏览量
2022-07-07
11:24:00
上传
评论
收藏 38KB RAR 举报
温馨提示
微信的一些接口资源包(PHP),个人经过转码,只适合放在thinkPHP的拓展目录中(extend)。 token->AccessToken.php 用户获取appid+appsecret换取AccessToken和ticket wxBizDataCrypt 微信数据解密 wxMsgCrypt 微信消息数据解密 wxpay 微信支付文档
资源详情
资源评论
资源推荐
收起资源包目录
tencent.rar (33个子文件)
tencent
wxpay
WxPayException.php 171B
WxPayApi.php 25KB
WxPayConfig.php 1KB
base
WxPayShortUrl.php 3KB
WxPayUnifiedOrder.php 13KB
WxPayCloseOrder.php 3KB
WxPayDownloadBill.php 4KB
WxPayMicroPay.php 11KB
WxPayJsApiPay.php 4KB
WxPayNotifyResults.php 555B
WxPayReverse.php 3KB
WxPayReport.php 11KB
WxPayDataBaseSignMd5.php 1KB
WxPayRefundQuery.php 5KB
WxPayRefund.php 8KB
WxPayBizPayUrl.php 3KB
WxPayNotifyReply.php 1KB
WxPayOrderQuery.php 3KB
WxPayDataBase.php 4KB
WxPayResults.php 3KB
OrderCreate.php 2KB
JsApiPay.php 8KB
WxPayConfigInterface.php 3KB
WxPayNotify.php 3KB
wxMsgCrypt
ErrorCode.php 1KB
WXBizMsgCrypt.php 4KB
PKCS7Encoder.php 1KB
XMLParse.php 1KB
PrpCrypt.php 4KB
SHA1.php 755B
wxBizDataCrypt
ErrorCode.php 538B
WXBizDataCrypt.php 1KB
token
AccessToken.php 4KB
共 33 条
- 1
chose2875
- 粉丝: 8
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0