mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2025-04-06 03:58:03 +08:00
[更新]完善测试案例代码
This commit is contained in:
parent
492f73f92e
commit
b07eacde23
@ -18,8 +18,8 @@ return [
|
|||||||
'appsecret' => '71308e96a204296c57d7cd4b21b883e8',
|
'appsecret' => '71308e96a204296c57d7cd4b21b883e8',
|
||||||
'encodingaeskey' => 'BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5',
|
'encodingaeskey' => 'BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5',
|
||||||
// 配置商户支付参数
|
// 配置商户支付参数
|
||||||
'mch_id' => "1235704602",
|
'mch_id' => "1332187001",
|
||||||
'mch_key' => 'IKI4kpHjU94ji3oqre5zYaQMwLHuZPmj',
|
'mch_key' => '11bd3d66d85f322a1e803cb587d18c3f',
|
||||||
// 配置商户支付双向证书目录
|
// 配置商户支付双向证书目录
|
||||||
'ssl_key' => '',
|
'ssl_key' => '',
|
||||||
'ssl_cer' => '',
|
'ssl_cer' => '',
|
||||||
|
37
Test/pay-close-order.php
Normal file
37
Test/pay-close-order.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 官方网站: http://think.ctolog.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 ( https://mit-license.org )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 1. 手动加载入口文件
|
||||||
|
include "../include.php";
|
||||||
|
|
||||||
|
// 2. 准备公众号配置参数
|
||||||
|
$config = include "./config.php";
|
||||||
|
|
||||||
|
// 3. 创建接口实例
|
||||||
|
$wechat = new \WeChat\Pay($config);
|
||||||
|
|
||||||
|
// 4. 组装参数,可以参考官方商户文档
|
||||||
|
$options = '1217752501201407033233368018';
|
||||||
|
$result = $wechat->closeOrder($options);
|
||||||
|
|
||||||
|
var_export($result);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
|
// 出错啦,处理下吧
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
40
Test/pay-download-bill.php
Normal file
40
Test/pay-download-bill.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 官方网站: http://think.ctolog.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 ( https://mit-license.org )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 1. 手动加载入口文件
|
||||||
|
include "../include.php";
|
||||||
|
|
||||||
|
// 2. 准备公众号配置参数
|
||||||
|
$config = include "./config.php";
|
||||||
|
|
||||||
|
// 3. 创建接口实例
|
||||||
|
$wechat = new \WeChat\Pay($config);
|
||||||
|
|
||||||
|
// 4. 组装参数,可以参考官方商户文档
|
||||||
|
$options = [
|
||||||
|
'bill_date' => '20171001',
|
||||||
|
'bill_type' => 'ALL',
|
||||||
|
];
|
||||||
|
$result = $wechat->billDownload($options);
|
||||||
|
|
||||||
|
var_export($result);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
|
// 出错啦,处理下吧
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
45
Test/pay-order-create.php
Normal file
45
Test/pay-order-create.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 官方网站: http://think.ctolog.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 ( https://mit-license.org )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 1. 手动加载入口文件
|
||||||
|
include "../include.php";
|
||||||
|
|
||||||
|
// 2. 准备公众号配置参数
|
||||||
|
$config = include "./config.php";
|
||||||
|
|
||||||
|
// 3. 创建接口实例
|
||||||
|
$wechat = new \WeChat\Pay($config);
|
||||||
|
|
||||||
|
// 4. 组装参数,可以参考官方商户文档
|
||||||
|
$options = [
|
||||||
|
'body' => '测试商品',
|
||||||
|
'out_trade_no' => time(),
|
||||||
|
'total_fee' => '1',
|
||||||
|
'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
|
||||||
|
'trade_type' => 'JSAPI',
|
||||||
|
'notify_url' => 'http://a.com/text.html',
|
||||||
|
'spbill_create_ip' => '127.0.0.1',
|
||||||
|
];
|
||||||
|
$result = $wechat->createOrder($options);
|
||||||
|
|
||||||
|
var_export($result);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
|
// 出错啦,处理下吧
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
40
Test/pay-order-query.php
Normal file
40
Test/pay-order-query.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 官方网站: http://think.ctolog.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 ( https://mit-license.org )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 1. 手动加载入口文件
|
||||||
|
include "../include.php";
|
||||||
|
|
||||||
|
// 2. 准备公众号配置参数
|
||||||
|
$config = include "./config.php";
|
||||||
|
|
||||||
|
// 3. 创建接口实例
|
||||||
|
$wechat = new \WeChat\Pay($config);
|
||||||
|
|
||||||
|
// 4. 组装参数,可以参考官方商户文档
|
||||||
|
$options = [
|
||||||
|
'transaction_id' => '1008450740201411110005820873',
|
||||||
|
// 'out_trade_no' => '商户订单号',
|
||||||
|
];
|
||||||
|
$result = $wechat->queryOrder($options);
|
||||||
|
|
||||||
|
var_export($result);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
|
// 出错啦,处理下吧
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
41
Test/pay-refund-create.php
Normal file
41
Test/pay-refund-create.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 官方网站: http://think.ctolog.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 ( https://mit-license.org )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 1. 手动加载入口文件
|
||||||
|
include "../include.php";
|
||||||
|
|
||||||
|
// 2. 准备公众号配置参数
|
||||||
|
$config = include "./config.php";
|
||||||
|
|
||||||
|
// 3. 创建接口实例
|
||||||
|
$wechat = new \WeChat\Pay($config);
|
||||||
|
|
||||||
|
// 4. 组装参数,可以参考官方商户文档
|
||||||
|
$options = [
|
||||||
|
'transaction_id' => '1008450740201411110005820873',
|
||||||
|
'total_fee' => '1',
|
||||||
|
'refund_fee' => '1',
|
||||||
|
];
|
||||||
|
$result = $wechat->refund($options);
|
||||||
|
|
||||||
|
var_export($result);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
|
// 出错啦,处理下吧
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
41
Test/pay-refund-query.php
Normal file
41
Test/pay-refund-query.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 官方网站: http://think.ctolog.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 ( https://mit-license.org )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 1. 手动加载入口文件
|
||||||
|
include "../include.php";
|
||||||
|
|
||||||
|
// 2. 准备公众号配置参数
|
||||||
|
$config = include "./config.php";
|
||||||
|
|
||||||
|
// 3. 创建接口实例
|
||||||
|
$wechat = new \WeChat\Pay($config);
|
||||||
|
|
||||||
|
// 4. 组装参数,可以参考官方商户文档
|
||||||
|
$options = [
|
||||||
|
'transaction_id' => '1008450740201411110005820873',
|
||||||
|
'total_fee' => '1',
|
||||||
|
'refund_fee' => '1',
|
||||||
|
];
|
||||||
|
$result = $wechat->refund($options);
|
||||||
|
|
||||||
|
var_export($result);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
|
// 出错啦,处理下吧
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
@ -63,8 +63,9 @@ class Pay
|
|||||||
* 统一下单
|
* 统一下单
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function order(array $options)
|
public function createOrder(array $options)
|
||||||
{
|
{
|
||||||
$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
|
$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
|
||||||
return $this->callPostApi($url, $options);
|
return $this->callPostApi($url, $options);
|
||||||
@ -74,6 +75,7 @@ class Pay
|
|||||||
* 查询订单
|
* 查询订单
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function queryOrder(array $options)
|
public function queryOrder(array $options)
|
||||||
{
|
{
|
||||||
@ -85,6 +87,7 @@ class Pay
|
|||||||
* 关闭订单
|
* 关闭订单
|
||||||
* @param string $out_trade_no 商户订单号
|
* @param string $out_trade_no 商户订单号
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function closeOrder($out_trade_no)
|
public function closeOrder($out_trade_no)
|
||||||
{
|
{
|
||||||
@ -96,6 +99,7 @@ class Pay
|
|||||||
* 申请退款
|
* 申请退款
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function refund(array $options)
|
public function refund(array $options)
|
||||||
{
|
{
|
||||||
@ -107,6 +111,7 @@ class Pay
|
|||||||
* 查询退款
|
* 查询退款
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function queryRefund(array $options)
|
public function queryRefund(array $options)
|
||||||
{
|
{
|
||||||
@ -118,6 +123,7 @@ class Pay
|
|||||||
* 交易保障
|
* 交易保障
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function report(array $options)
|
public function report(array $options)
|
||||||
{
|
{
|
||||||
@ -129,6 +135,7 @@ class Pay
|
|||||||
* 授权码查询openid
|
* 授权码查询openid
|
||||||
* @param string $authCode 扫码支付授权码,设备读取用户微信中的条码或者二维码信息
|
* @param string $authCode 扫码支付授权码,设备读取用户微信中的条码或者二维码信息
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function queryAuthCode($authCode)
|
public function queryAuthCode($authCode)
|
||||||
{
|
{
|
||||||
@ -140,6 +147,7 @@ class Pay
|
|||||||
* 转换短链接
|
* 转换短链接
|
||||||
* @param string $longUrl 需要转换的URL,签名用原串,传输需URLencode
|
* @param string $longUrl 需要转换的URL,签名用原串,传输需URLencode
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function shortUrl($longUrl)
|
public function shortUrl($longUrl)
|
||||||
{
|
{
|
||||||
@ -151,8 +159,9 @@ class Pay
|
|||||||
* 下载对账单
|
* 下载对账单
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function bill(array $options)
|
public function billDownload(array $options)
|
||||||
{
|
{
|
||||||
$url = 'https://api.mch.weixin.qq.com/pay/downloadbill';
|
$url = 'https://api.mch.weixin.qq.com/pay/downloadbill';
|
||||||
return $this->callPostApi($url, $options);
|
return $this->callPostApi($url, $options);
|
||||||
@ -163,6 +172,7 @@ class Pay
|
|||||||
* 拉取订单评价数据
|
* 拉取订单评价数据
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function billCommtent(array $options)
|
public function billCommtent(array $options)
|
||||||
{
|
{
|
||||||
@ -195,8 +205,8 @@ class Pay
|
|||||||
{
|
{
|
||||||
ksort($data);
|
ksort($data);
|
||||||
list($key, $str) = [$this->config->get('mch_key'), ''];
|
list($key, $str) = [$this->config->get('mch_key'), ''];
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $k => $v) {
|
||||||
$str .= "{$key}={$value}&";
|
$str .= "{$k}={$v}&";
|
||||||
}
|
}
|
||||||
return strtoupper(hash_hmac('SHA256', "{$str}key={$key}", $key));
|
return strtoupper(hash_hmac('SHA256', "{$str}key={$key}", $key));
|
||||||
}
|
}
|
||||||
@ -207,13 +217,14 @@ class Pay
|
|||||||
* @param array $data 接口参数
|
* @param array $data 接口参数
|
||||||
* @param bool $isCert 是否需要使用双向证书
|
* @param bool $isCert 是否需要使用双向证书
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws InvalidResponseException
|
||||||
*/
|
*/
|
||||||
public function callPostApi($url, array $data, $isCert = false)
|
public function callPostApi($url, array $data, $isCert = false)
|
||||||
{
|
{
|
||||||
$option = [];
|
$option = [];
|
||||||
if ($isCert) {
|
if ($isCert) {
|
||||||
foreach (['ssl_cer', 'ssl_key'] as $key) {
|
foreach (['ssl_cer', 'ssl_key'] as $key) {
|
||||||
if (empty($options['ssl_cer'])) {
|
if (empty($options[$key])) {
|
||||||
throw new InvalidArgumentException("Missing Config -- [{$key}]", '0');
|
throw new InvalidArgumentException("Missing Config -- [{$key}]", '0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,6 +234,10 @@ class Pay
|
|||||||
$params = $this->params->merge($data);
|
$params = $this->params->merge($data);
|
||||||
$params['sign_type'] = 'HMAC-SHA256';
|
$params['sign_type'] = 'HMAC-SHA256';
|
||||||
$params['sign'] = $this->getPaySign($params);
|
$params['sign'] = $this->getPaySign($params);
|
||||||
return Tools::xml2arr(Tools::post($url, Tools::arr2xml($params), $option));
|
$result = Tools::xml2arr(Tools::post($url, Tools::arr2xml($params), $option));
|
||||||
|
if ($result['return_code'] !== 'SUCCESS') {
|
||||||
|
throw new InvalidResponseException($result['return_msg'], '0');
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user