Compare commits

...

27 Commits

Author SHA1 Message Date
邹景立
5b6b09b955 feat: 添加获取开卡插件参数 2024-11-18 22:10:27 +08:00
邹景立
4a624380ea fix: 修复接口并增加完善 2024-11-08 20:50:57 +08:00
邹景立
1701ad0e48 格式化代码 2024-11-07 22:17:20 +08:00
邹景立
bd5b36373c fix: 增加小程序运费险 2024-11-07 22:16:24 +08:00
邹景立
6e349d997d fix: 调整代码去除不需要的代码 2024-10-17 16:15:06 +08:00
邹景立
c909d97e12 fix: 代码使用 php5.4 格式化 2024-10-17 16:09:27 +08:00
邹景立
ff8a0eacf0
Merge pull request #88 from fxiaotao/master
新增通商户消费者投诉2.0
2024-10-17 16:03:49 +08:00
承诺
4eec331f7f
新增通商户消费者投诉2.0 2024-10-17 12:01:29 +08:00
邹景立
c4db8b7ee8 Update Ecommerce.php 2024-10-02 00:01:26 +08:00
邹景立
4cd6c1206f fix: 修正一处代码错误 2024-09-28 21:43:54 +08:00
邹景立
a21c12f775 fix: 更新代码规范,兼容 PHP5.4 2024-09-28 21:41:18 +08:00
邹景立
bc70e420bd fix: 增加 平台收付通 接口 2024-09-28 21:40:43 +08:00
邹景立
02d9243b40 fix: 微信V3支付增加文件上传接口 2024-09-28 21:40:25 +08:00
邹景立
9f27480860 fix: 更新退款通知处理 2024-09-25 13:08:34 +08:00
邹景立
0f9023dfbf fix: 支付通知允许传数组内容 2024-09-20 15:45:06 +08:00
邹景立
8c0a87252c fix: 修改项目描述信息 2024-09-20 15:00:50 +08:00
邹景立
db5b813d87 fix: 更新缓存配置描述 2024-09-20 14:27:26 +08:00
邹景立
3fc888a1ac fix: 更新项目配置描述 2024-09-20 14:25:33 +08:00
邹景立
0e70c7fcd7 feat: 增加小程序客服相关接口 2024-09-19 10:53:42 +08:00
邹景立
679802ad80 fix: 微信小程序服务市场接口 2024-09-14 16:09:52 +08:00
邹景立
f3e61e2c9d fix: 更新小程序 Live 接口及 Media 接口 2024-08-28 11:56:35 +08:00
邹景立
8a11271805 fix: 增加微信V3券卡管理 2024-08-19 12:42:08 +08:00
邹景立
d422e5dc17 fix: 完善小程序 Live 接口 2024-08-18 22:32:01 +08:00
邹景立
e750ac9cd2 fix: 修正微信V3提现接口参数处理 2024-08-05 21:32:30 +08:00
邹景立
8c84c053d3 fix: 修改兼容文件加载配置 2024-08-05 20:20:35 +08:00
邹景立
28de3a64cd fix: 增加 array_column 兼容函数 2024-08-04 23:09:55 +08:00
邹景立
65c3dca0fd fix: 降低 PHP 版本限制为 5.4 2024-08-04 23:09:34 +08:00
23 changed files with 2284 additions and 33 deletions

View File

@ -628,4 +628,17 @@ class Card extends BasicWeChat
$url = "https://api.weixin.qq.com/card/pay/getorderlist?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data);
}
/**
* 获取开卡插件参数
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getActivateUrl(array $data)
{
$url = "https://api.weixin.qq.com/card/membercard/activate/geturl?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data);
}
}

View File

@ -92,13 +92,13 @@ class BasicWePay
/**
* 获取微信支付通知
* @param string $xml
* @param string|array $xml
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getNotify($xml = '')
{
$data = Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
$data = is_array($xml) ? $xml : Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
if (isset($data['sign']) && $this->getPaySign($data) === $data['sign']) {
return $data;
}

View File

@ -20,6 +20,32 @@ use WeChat\Exceptions\InvalidArgumentException;
use WeChat\Exceptions\InvalidResponseException;
use WeChat\Exceptions\LocalCacheException;
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// return $value;
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// return $value;
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// return true;
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];
/**
* 网络请求支持
* Class Tools
@ -34,14 +60,14 @@ class Tools
public static $cache_path = null;
/**
* 缓存写入操作
* 缓存读写配置
* @var array
*/
public static $cache_callable = [
'set' => null, // 写入缓存
'get' => null, // 获取缓存
'del' => null, // 删除缓存
'put' => null, // 写入文件
'set' => null, // 写入缓存 ($name,$value='',$expired=3600):string
'get' => null, // 获取缓存 ($name):mixed|null
'del' => null, // 删除缓存 ($name):boolean
'put' => null, // 写入文件 ($name,$content):string
];
/**
@ -67,7 +93,7 @@ class Tools
/**
* 获取输入对象
* @return false|mixed|string
* @return string
*/
public static function getRawInput()
{
@ -78,6 +104,16 @@ class Tools
}
}
/**
* 设置输入内容
* @param string $rawInput
* @return void
*/
public static function setRawInput($rawInput)
{
$GLOBALS['HTTP_RAW_POST_DATA'] = $rawInput;
}
/**
* 根据文件后缀获取文件类型
* @param string|array $ext 文件后缀
@ -353,7 +389,8 @@ class Tools
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
list($content) = [curl_exec($curl), curl_close($curl)];
$content = curl_exec($curl);
curl_close($curl);
// 清理 CURL 缓存文件
if (!empty(self::$cache_curl)) foreach (self::$cache_curl as $key => $file) {
Tools::delCache($file);

209
WeMini/Custom.php Normal file
View File

@ -0,0 +1,209 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 小程序客服服务
* Class Custom
* @package WeMini
*/
class Custom extends BasicWeChat
{
/**
* 创建商户
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function businessRegister($data)
{
$url = 'https://api.weixin.qq.com/cgibin/business/register?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 更新商户信息
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function businessUpdate($data)
{
$url = 'https://api.weixin.qq.com/cgibin/business/update?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 拉取单个商户信息
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function businessGet($data)
{
$url = 'https://api.weixin.qq.com/cgibin/business/get?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 拉取多个商户信息
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function businessList($data)
{
$url = 'https://api.weixin.qq.com/cgibin/business/list?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 发送客服消息
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function businessSend($data)
{
$url = 'https://api.weixin.qq.com/cgibin/message/custom/business/send?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 客服输入状态
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function businessTyping($data)
{
$url = 'https://api.weixin.qq.com/cgibin/message/custom/business/typing?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取客服基本信息
* @param string $business_id 客服子商户的business_id对于普通小程序客服不需要填business_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getKfList($business_id = '')
{
$url = 'https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=ACCESS_TOKEN';
if (!empty($business_id)) {
$url .= '&business_id=' . $business_id;
}
return $this->callGetApi($url);
}
/**
* 获取在线客服列表
* @param string $business_id 客服子商户的business_id对于普通小程序客服不需要填business_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getOnlineKfList($business_id = '')
{
$url = 'https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token=ACCESS_TOKEN';
if (!empty($business_id)) {
$url .= '&business_id=' . $business_id;
}
return $this->callGetApi($url);
}
/**
* 客服输入状态
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addKfAccount($data)
{
$url = 'https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 删除客服账号
* @param string $kf_openid 客服openid
* @param string $business_id 客服子商户的business_id对于普通小程序客服不需要填business_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delKfAccount($kf_openid, $business_id = '')
{
$url = 'https://api.weixin.qq.com/customservice/kfaccount/del?access_token=ACCESS_TOKEN&kf_openid=' . $kf_openid;
if (!empty($business_id)) {
$url .= '&business_id=' . $business_id;
}
return $this->callGetApi($url);
}
/**
* 设置客服管理员
* @param string $kf_openid 客服openid
* @param string $business_id 客服子商户的business_id对于普通小程序客服不需要填business_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setKfAdmin($kf_openid, $business_id = '')
{
$url = 'https://api.weixin.qq.com/customservice/kfaccount/setadmin?access_token=ACCESS_TOKEN&kf_openid=' . $kf_openid;
if (!empty($business_id)) {
$url .= '&business_id=' . $business_id;
}
return $this->callGetApi($url);
}
/**
* 取消客服管理员
* @param string $kf_openid 客服openid
* @param string $business_id 客服子商户的business_id对于普通小程序客服不需要填business_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function cancelKfAdmin($kf_openid, $business_id = '')
{
$url = 'https://api.weixin.qq.com/customservice/kfaccount/canceladmin?access_token=ACCESS_TOKEN&kf_openid=' . $kf_openid;
if (!empty($business_id)) {
$url .= '&business_id=' . $business_id;
}
return $this->callGetApi($url);
}
}

209
WeMini/Insurance.php Normal file
View File

@ -0,0 +1,209 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 小程序运费险
* Class Insurance
* @package WeMini
*/
class Insurance extends BasicWeChat
{
/**
* 开通无忧退货接口
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function open()
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/open?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, [], true);
}
/**
* 查询开通状态接口
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryOpen()
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/query_open?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, [], true);
}
/**
* 投保接口(发货时投保)
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createOrder($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/createorder?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 理赔接口 (收到用户退货后再触发)
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function claim($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/claim?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 申请充值订单号接口 (支持自定义金额)
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createChargeId($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/createchargeid?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 申请支付接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function applyPay($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/applypay?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 拉取充值订单信息接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getPayOrderList($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/getpayorderlist?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 退款接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function refund($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/refund?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 拉取摘要接口 (查询当前保费、投保单量、理赔单量、账号余额等信息)
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getSummary($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/getsummary?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 拉取保单信息接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getOrderList($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/getorderlist?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 设置告警余额接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateNotifyFunds($data)
{
$url = 'https://api.weixin.qq.com/wxa/business/insurance_freight/update_notify_funds?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 创建退货 ID
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function returnAdd($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/delivery/no_worry_return/add?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 查询退货 ID 状态
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function returnGet($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/delivery/no_worry_return/get?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 查解绑退货 ID
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function returnUbind($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/delivery/no_worry_return/unbind?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

View File

@ -158,14 +158,361 @@ class Live extends BasicWeChat
/**
* 获取商品列表
* @param integer $offset 分页条数起点
* @param integer $status 商品状态0未审核。1审核中2审核通过3审核驳回
* @param integer $limit 分页大小默认30不超过100
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGoods($offset, $status, $limit = 30)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved?access_token=ACCESS_TOKEN&offset={$offset}&limit={$limit}&status={$status}";
return $this->callGetApi($url);
}
/**
* 删除直播间
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGoods($data)
public function delLive($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved?access_token=ACCESS_TOKEN";
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/deleteroom?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 编辑直播间
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function editLive($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/editroom?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 获取直播间推流地址
* @param string $roomId
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getPushUrl($roomId)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getpushurl?access_token=ACCESS_TOKEN&roomId={$roomId}";
return $this->callGetApi($url);
}
/**
* 获取直播间分享二维码
* @param string $roomId
* @param string $params
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getShareCode($roomId, $params = '')
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getsharedcode?access_token=ACCESS_TOKEN&roomId={$roomId}&params={$params}";
return $this->callGetApi($url);
}
/**
* 添加管理直播间小助手
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addAssistant($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/addassistant?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 修改管理直播间小助手
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function modifyAssistant($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 删除管理直播间小助手
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function removeAssistant($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/removeassistant?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 查询管理直播间小助手
* @param string $roomId
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getAssistantList($roomId)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist?access_token=ACCESS_TOKEN&roomId={$roomId}";
return $this->callGetApi($url);
}
/**
* 添加主播副号
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addSubAnchor($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/addsubanchor?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 修改主播副号
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function modifySubAnchor($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/modifysubanchor?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 修删除主播副号
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delSubAnchor($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/deletesubanchor?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 查询除主播副号
* @param string $roomId
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getSubAnchor($roomId)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getsubanchor?access_token=ACCESS_TOKEN&roomId={$roomId}";
return $this->callGetApi($url);
}
/**
* 开启/关闭直播间官方收录
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateFeedPublic($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatefeedpublic?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 开启/关闭回放功能
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateReplay($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatereplay?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 开启/关闭客服功能
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateKf($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatekf?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 开启/关闭直播间全局禁言
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateComment($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatecomment?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 上下架商品
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function goodsOnsale($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/onsale?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 删除直播间商品
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function goodsDeleteInRoom($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 推送商品
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function goodsPush($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/push?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 商品排序
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function goodsSort($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/sort?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 下载商品讲解视频
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getVideo($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 获取长期订阅用户
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getFollowers($data)
{
$url = "https://api.weixin.qq.com/wxa/business/get_wxa_followers?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 长期订阅群发接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function pushMessage($data)
{
$url = "https://api.weixin.qq.com/wxa/business/push_message?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 设置成员角色
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addRole($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/role/addrole?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 解除成员角色
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delRole($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/role/deleterole?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 查询成员角色
* @param int $role
* @param int $offset
* @param int $limit
* @param string $keyword
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getRole($role = -1, $offset = 0, $limit = 30, $keyword = '')
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/role/getrolelist?access_token=ACCESS_TOKEN&offset={$offset}&limit={$limit}&keyword={$keyword}&role={$role}";
return $this->callGetApi($url);
}
}

View File

@ -110,7 +110,7 @@ class Logistics extends BasicWeChat
*/
public function getQuota($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token=ACCESS_TOKEN';
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/quota/get?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
@ -191,4 +191,47 @@ class Logistics extends BasicWeChat
$url = 'https://api.weixin.qq.com/cgi-bin/express/delivery/path/update?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 绑定/解绑物流账号
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function bindAccount($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/account/bind?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取所有绑定的物流账号
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getAllAccount($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/account/getall?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 批量获取运单数据
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function batchGetOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/order/batchget?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

55
WeMini/Market.php Normal file
View File

@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 微信小程序服务市场
* Class Ocr
* @package WeMini
*/
class Market extends BasicWeChat
{
/**
* 调用服务平台上架的API
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function invoke($data)
{
$url = 'https://api.weixin.qq.com/wxa/servicemarket?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取服务市场返回的数据
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function retrieve($data)
{
$url = 'https://api.weixin.qq.com/wxa/servicemarketretrieve?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

55
WeMini/Media.php Normal file
View File

@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
/**
* 小程序素材操作
* Class Media
* @package WeMini
*/
class Media extends BasicWeChat
{
/**
* 获取客服消息内的临时素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get($media_id)
{
$url = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=' . $media_id;
return $this->callGetApi($url);
}
/**
* 新增图片素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function upload($filename)
{
$url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=image';
return $this->callPostApi($url, ['media' => Tools::createCurlFile($filename)], false);
}
}

View File

@ -57,14 +57,14 @@ class Refund extends BasicWePay
/**
* 获取退款通知
* @param string $xml
* @param string|array $xml
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getNotify($xml = '')
{
$data = Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
$data = is_array($xml) ? $xml : Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS') {
throw new InvalidResponseException('获取退款通知XML失败');
}

147
WePayV3/Complaints.php Normal file
View File

@ -0,0 +1,147 @@
<?php
namespace WePayV3;
use WePayV3\Contracts\BasicWePay;
/**
* 普通商户消费者投诉2.0
* @class Complaints
* @package WePayV3
*/
class Complaints extends BasicWePay
{
/**
* 查询投诉列表
* @param int $offset 分页开始位置
* @param int $limit 分页大小
* @param String $begin_date 开始日期
* @param String $end_date 结束日期
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function complaintList($offset, $limit, $begin_date, $end_date)
{
$mchId = $this->config['mch_id'];
$pathinfo = "/v3/merchant-service/complaints-v2?limit={$limit}&offset={$offset}&begin_date={$begin_date}&end_date={$end_date}&complainted_mchid={$mchId}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询投诉详情
* @param string $complaint_id 被投诉单号
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function complaintDetails($complaint_id)
{
$pathinfo = "/v3/merchant-service/complaints-v2/{$complaint_id}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询投诉协商历史
* @param string $complaint_id 被投诉单号
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function negotiationHistory($complaint_id)
{
$pathinfo = "/v3/merchant-service/complaints-v2/{$complaint_id}/negotiation-historys";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 创建投诉通知回调地址
* @param string $url 回调通知地址
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function CreateComplaintsNotify($url)
{
return $this->doRequest('POST', '/v3/merchant-service/complaint-notifications', json_encode(['url' => $url], JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询投诉通知回调地址
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryComplaintsNotify()
{
return $this->doRequest('GET', '/v3/merchant-service/complaint-notifications', '', true);
}
/**
* 更新投诉通知回调地址
* @param string $url 回调通知地址
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function updateComplaintsNotify($url)
{
return $this->doRequest('PUT', '/v3/merchant-service/complaint-notifications', json_encode(['url' => $url], JSON_UNESCAPED_UNICODE), true);
}
/**
* 删除投诉通知回调地址
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function deleteComplaintsNotify()
{
return $this->doRequest('DELETE', '/v3/merchant-service/complaint-notifications', '', true);
}
/**
* 回复投诉
* @param string $complaint_id 被投诉单号
* @param array $content 回复内容
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function replyInfo($complaint_id, array $content)
{
$content['complainted_mchid'] = $this->config['mch_id'];
$pathinfo = "/v3/merchant-service/complaints-v2/{$complaint_id}/response";
return $this->doRequest('POST', $pathinfo, json_encode($content, JSON_UNESCAPED_UNICODE), true);
}
/**
* 反馈处理完成
* @param string $complaint_id 被投诉单号
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function completeComplaints($complaint_id)
{
$mchId = $this->config['mch_id'];
$pathinfo = "/v3/merchant-service/complaints-v2/{$complaint_id}/complete";
return $this->doRequest('POST', $pathinfo, json_encode(['complainted_mchid' => $mchId], JSON_UNESCAPED_UNICODE), true);
}
/**
* 图片请求接口
* @param string $pathinfo
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function downLoadImg($pathinfo)
{
return $this->doRequest('GET', $pathinfo, '', true, false);
}
/**
* 图片上传接口
* @param array $imginfo
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function uploadImg(array $imginfo)
{
return $this->doRequest('POST', '/v3/merchant-service/images/upload', json_encode($imginfo, JSON_UNESCAPED_UNICODE), true);
}
}

View File

@ -206,6 +206,83 @@ abstract class BasicWePay
return $isjson ? json_decode($content, true) : $content;
}
/**
* 模拟发起上传请求
* @param string $pathinfo 请求路由
* @param string $filename 文件本地路径
* @param boolean $verify 是否验证
* @param boolean $isjson 返回JSON
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function doUpload($pathinfo, $filename, $verify = false, $isjson = true)
{
$filedata = file_get_contents($filename);
$fileinfo = [
'sha256' => hash("sha256", $filedata),
'filename' => basename($filename)
];
$jsondata = json_encode($fileinfo);
list($time, $nonce) = [time(), uniqid() . rand(1000, 9999)];
$signstr = join("\n", ['POST', $pathinfo, $time, $nonce, $jsondata, '']);
// 生成签名
$sign = $this->signBuild($signstr);
// 生成数据签名TOKEN
$token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$this->config['mch_id'], $nonce, $time, $this->config['cert_serial'], $sign
);
$location = (preg_match('|^https?://|', $pathinfo) ? '' : $this->base) . $pathinfo;
$boundary = mt_rand(100000000000000000, 999999999999999999);
$header = [
'Accept: application/json',
"Content-Type: multipart/form-data; boundary={$boundary}",
'User-Agent: https://thinkadmin.top',
"Authorization: WECHATPAY2-SHA256-RSA2048 {$token}",
"serial_no: {$this->config['mp_cert_serial']}",
"nonce_str: {$nonce}",
"signature: {$sign}"
];
$line = [];
$line[] = "--{$boundary}";
$line[] = "Content-Disposition: form-data; name=\"meta\"";
$line[] = "Content-Type: application/json";
$line[] = "";
$line[] = $jsondata;
$line[] = "--{$boundary}";
$line[] = "Content-Disposition: form-data; name=\"file\"; filename=\"{$fileinfo['filename']}\";";
$line[] = "Content-Type: image/jpg";
$line[] = "";
$line[] = $filedata;
$line[] = "--{$boundary}--";
$postdata = join("\r\n", $line);
list($header, $content) = $this->_doRequestCurl('POST', $location, [
'data' => $postdata, 'header' => $header,
]);
if ($verify) {
$headers = [];
foreach (explode("\n", $header) as $line) {
if (stripos($line, 'Wechatpay') !== false) {
list($name, $value) = explode(':', $line);
list(, $keys) = explode('wechatpay-', strtolower($name));
$headers[$keys] = trim($value);
}
}
try {
if (empty($headers)) {
return $isjson ? json_decode($content, true) : $content;
}
$string = join("\n", [$headers['timestamp'], $headers['nonce'], $content, '']);
if (!$this->signVerify($string, $headers['signature'], $headers['serial'])) {
throw new InvalidResponseException('验证响应签名失败');
}
} catch (\Exception $exception) {
throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
}
}
return $isjson ? json_decode($content, true) : $content;
}
/**
* 通过CURL模拟网络请求
* @param string $method 请求方法

156
WePayV3/Coupon.php Normal file
View File

@ -0,0 +1,156 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePayV3;
use WeChat\Exceptions\InvalidResponseException;
use WePayV3\Contracts\BasicWePay;
/**
* 微信支付代金券
* @class Coupon
* @package WePayV3
*/
class Coupon extends BasicWePay
{
/**
* 创建代金券批次
* @param array $data
* @return array|string
* @throws InvalidResponseException
*/
public function stocksCreate(array $data)
{
$path = "/v3/marketing/favor/coupon-stocks";
return $this->doRequest('POST', $path, json_encode($data), true);
}
/**
* 激活代金券批次
* @param string $stock_id 批次号
* @param string $stock_creator_mchid 创建批次的商户号
* @return array|string
* @throws InvalidResponseException
*/
public function stocksStart($stock_id, $stock_creator_mchid)
{
$path = "/v3/marketing/favor/stocks/{$stock_id}/start";
return $this->doRequest('POST', $path, json_encode(['stock_creator_mchid' => $stock_creator_mchid]), true);
}
/**
* 暂停代金券批次
* @param string $stock_id 批次号
* @param string $stock_creator_mchid 创建批次的商户号
* @return array|string
* @throws InvalidResponseException
*/
public function stocksPause($stock_id, $stock_creator_mchid)
{
$path = "/v3/marketing/favor/stocks/{$stock_id}/pause";
return $this->doRequest('POST', $path, json_encode(['stock_creator_mchid' => $stock_creator_mchid]), true);
}
/**
* 重启代金券批次
* @param string $stock_id 批次号
* @param string $stock_creator_mchid 创建批次的商户号
* @return array|string
* @throws InvalidResponseException
*/
public function stocksRestart($stock_id, $stock_creator_mchid)
{
$path = "/v3/marketing/favor/stocks/{$stock_id}/restart";
return $this->doRequest('POST', $path, json_encode(['stock_creator_mchid' => $stock_creator_mchid]), true);
}
/**
* 查询批次详情
* @param string $stock_id 批次号
* @param string $stock_creator_mchid 创建批次的商户号
* @return array|string
* @throws InvalidResponseException
*/
public function stocksDetail($stock_id, $stock_creator_mchid)
{
$path = "/v3/marketing/favor/stocks/{$stock_id}?stock_creator_mchid={$stock_creator_mchid}";
return $this->doRequest('GET', $path, '', true);
}
/**
* 代金券批次可用商品
* @param array $param
* @return array|string
* @throws InvalidResponseException
*/
public function stocksItems(array $param)
{
$path = "/v3/marketing/favor/stocks/{$param['stock_id']}/items ";
return $this->doRequest('POST', $path, json_encode($param), true);
}
/**
* 设置消息通知地址
* @param array $param
* @return array|string
* @throws InvalidResponseException
*/
public function setCallbacks(array $param)
{
$path = "/v3/marketing/favor/callbacks";
return $this->doRequest('POST', $path, json_encode($param), true);
}
/**
* 发放代金券批次
* @param array $param 请求参数
* @return array|string
* @throws InvalidResponseException
*/
public function couponsSend(array $param)
{
$path = "/v3/marketing/favor/users/{$param['openid']}/coupons";
return $this->doRequest('POST', $path, json_encode($param), true);
}
/**
* 根据商户号查用户的券
* @param array $param 请求参数
* @return array|string
* @throws InvalidResponseException
*/
public function couponsList(array $param)
{
$path = "/v3/marketing/favor/users/{$param['openid']}/coupons";
return $this->doRequest('POST', $path, json_encode($param), true);
}
/**
* 查询代金券详情
* @param string $openid 用户openid
* @param string $coupon_id 代金券id
* @param string $appid 公众账号ID
* @return array|string
* @throws InvalidResponseException
*/
public function couponsDetail($openid, $coupon_id, $appid)
{
$path = "/v3/marketing/favor/users/{$openid}/coupons/{$coupon_id}?appid={$appid}";
return $this->doRequest('GET', $path, '', true);
}
}

766
WePayV3/Ecommerce.php Normal file
View File

@ -0,0 +1,766 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePayV3;
use WeChat\Contracts\Tools;
use WePayV3\Contracts\BasicWePay;
/**
* 平台收付通
* @class Ecommerce
* @package WePayV3
*/
class Ecommerce extends BasicWePay
{
/**
* 提交申请单(商户进件)
* @param array $data 进件参数
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function ecommerceApplyments($data)
{
if (isset($data['id_card_info'])) {
if (isset($data['id_card_info']['id_card_name'])) $data['id_card_info']['id_card_name'] = $this->rsaEncode($data['id_card_info']['id_card_name']);
if (isset($data['id_card_info']['id_card_number'])) $data['id_card_info']['id_card_number'] = $this->rsaEncode($data['id_card_info']['id_card_number']);
}
if (isset($data['id_doc_info'])) {
if (isset($data['id_doc_info']['id_doc_name'])) $data['id_doc_info']['id_doc_name'] = $this->rsaEncode($data['id_doc_info']['id_doc_name']);
if (isset($data['id_doc_info']['id_doc_number'])) $data['id_doc_info']['id_doc_number'] = $this->rsaEncode($data['id_doc_info']['id_doc_number']);
}
if (isset($data['contact_info'])) {
if (isset($data['contact_info']['contact_name'])) $data['contact_info']['contact_name'] = $this->rsaEncode($data['contact_info']['contact_name']);
if (isset($data['contact_info']['contact_id_card_number'])) $data['contact_info']['contact_id_card_number'] = $this->rsaEncode($data['contact_info']['contact_id_card_number']);
if (isset($data['contact_info']['mobile_phone'])) $data['contact_info']['mobile_phone'] = $this->rsaEncode($data['contact_info']['mobile_phone']);
}
if (isset($data['account_info'])) {
if (isset($data['account_info']['account_name'])) $data['account_info']['account_name'] = $this->rsaEncode($data['account_info']['account_name']);
if (isset($data['account_info']['account_number'])) $data['account_info']['account_number'] = $this->rsaEncode($data['account_info']['account_number']);
}
if (!empty($data['ubo_info_list'])) {
$data['ubo_info_list'] = array_map(function ($item) {
$item['ubo_id_doc_name'] = $this->rsaEncode($item['ubo_id_doc_name']);
$item['ubo_id_doc_number'] = $this->rsaEncode($item['ubo_id_doc_number']);
$item['ubo_id_doc_address'] = $this->rsaEncode($item['ubo_id_doc_address']);
return $item;
}, $data['ubo_info_list']);
}
return $this->doRequest('POST', '/v3/ecommerce/applyments/', json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 通过业务申请编号查询申请状态(商户进件)
* @param string $out_request_no 业务申请编号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function ecommerceApplymentsByRequestNo($out_request_no)
{
$pathinfo = "/v3/ecommerce/applyments/out-request-no/{$out_request_no}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 通过申请单ID查询申请状态商户进件
* @param string $applyment_id 微信支付申请单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function ecommerceApplymentsByApplymentId($applyment_id)
{
$pathinfo = "/v3/ecommerce/applyments/{$applyment_id}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 修改结算账户(商户进件)
* @param string $sub_mchid 特约商户/二级商户号
* @param array $data 包体参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function modifySettlement($sub_mchid, $data)
{
$pathinfo = "/v3/apply4sub/sub_merchants/{$sub_mchid}/modify-settlement";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询结算账户修改申请状态(商户进件)
* @param string $sub_mchid 特约商户/二级商户号
* @param string $application_no 修改结算账户申请单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function modifySettlementResult($sub_mchid, $application_no)
{
$pathinfo = "/v3/apply4sub/sub_merchants/{$sub_mchid}/application/{$application_no}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询结算账户(商户进件)
* @param string $sub_mchid 特约商户/二级商户号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getSettlement($sub_mchid)
{
$pathinfo = "/v3/apply4sub/sub_merchants/{$sub_mchid}/settlement";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 上传文件(商户进件)
* @param string $filename 文件目录
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function mediaUpload($filename)
{
return $this->doUpload('/v3/merchant/media/upload', $filename, true);
}
/**
* APP下单普通支付
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function transactionsApp($data)
{
$pathinfo = "/v3/pay/partner/transactions/app";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* JSAPI下单普通支付
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function transactionsJsapi($data)
{
$pathinfo = "/v3/pay/partner/transactions/jsapi";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* Native下单普通支付
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function transactionsNative($data)
{
$pathinfo = "/v3/pay/partner/transactions/native";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* H5下单普通支付
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function transactionsH5($data)
{
$pathinfo = "/v3/pay/partner/transactions/h5";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 微信支付订单号查询订单(普通支付)
* @param string $transaction_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getTransactionsById($transaction_id)
{
$pathinfo = "/v3/pay/partner/transactions/id/{$transaction_id}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 微信支付商户订单号查询订单(普通支付)
* @param string $out_trade_no
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getTransactionsByTradeNo($out_trade_no)
{
$pathinfo = "/v3/pay/partner/transactions/out-trade-no/{$out_trade_no}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 关闭订单(普通支付)
* @param string $out_trade_no 商户订单号
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function transactionsClose($out_trade_no, $data)
{
$pathinfo = "/v3/pay/partner/transactions/out-trade-no/{$out_trade_no}/close";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* JSAPI支付合单下单
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function combineTransactionsJsapi($data)
{
$pathinfo = "/v3/combine-transactions/jsapi";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* APP支付合单下单
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function combineTransactionsApp($data)
{
$pathinfo = "/v3/combine-transactions/app";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* H5支付合单下单
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function combineTransactionsH5($data)
{
$pathinfo = "/v3/combine-transactions/h5";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* Native支付合单下单
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function combineTransactionsNative($data)
{
$pathinfo = "/v3/combine-transactions/native";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 合单查询(合单支付)
* @param string $combine_out_trade_no
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getCombineTransactionsByTradeNo($combine_out_trade_no)
{
$pathinfo = "/v3/combine-transactions/out-trade-no/{$combine_out_trade_no}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 合单关单(合单下单)
* @param $combine_out_trade_no
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function combineTransactionsClose($combine_out_trade_no, $data)
{
$pathinfo = "/v3/combine-transactions/out-trade-no/{$combine_out_trade_no}/close";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 请求分账(分账)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function profitsharingOrders($data)
{
$pathinfo = "/v3/ecommerce/profitsharing/orders";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询分账结果(分账)
* @param array $param
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryProfitsharingOrders($param = [])
{
$pathinfo = "/v3/ecommerce/profitsharing/orders?" . http_build_query($param);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 请求分账回退(分账)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function profitsharingReturnOrders($data)
{
$pathinfo = "/v3/ecommerce/profitsharing/returnorders";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询分账回退结果(分账)
* @param array $param
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryProfitsharingReturnOrders($param = [])
{
$pathinfo = "/v3/ecommerce/profitsharing/returnorders?" . http_build_query($param);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 完结分账(分账)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function profitsharingFinishOrder($data)
{
$pathinfo = "/v3/ecommerce/profitsharing/finish-order";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询订单剩余待分金额(分账)
* @param string $transaction_id 微信订单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function profitsharingReturnOrdersAmounts($transaction_id)
{
$pathinfo = "/v3/ecommerce/profitsharing/orders/{$transaction_id}/amounts";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 添加分账接收方(分账)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function profitsharingReceiversAdd($data)
{
$pathinfo = "/v3/ecommerce/profitsharing/receivers/add";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 添加分账接收方(分账)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function profitsharingReceiversDelete($data)
{
$pathinfo = "/v3/ecommerce/profitsharing/receivers/delete";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 请求补差(补差)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function subsidiesCreate($data)
{
$pathinfo = "/v3/ecommerce/subsidies/create";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 请求补差回退(补差)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function subsidiesReturn($data)
{
$pathinfo = "/v3/ecommerce/subsidies/return";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 取消补差(补差)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function subsidiesCancel($data)
{
$pathinfo = "/v3/ecommerce/subsidies/cancel";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 申请退款(退款)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function refundsApply($data)
{
$pathinfo = "/v3/ecommerce/refunds/apply";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询单笔退款(按商户退款单号)(退款)
* @param string $refund_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryRefundsById($refund_id)
{
$pathinfo = "/v3/ecommerce/refunds/id/{$refund_id}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询单笔退款(按商户退款单号)(退款)
* @param string $out_refund_no
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryRefundsByNo($out_refund_no)
{
$pathinfo = "/v3/ecommerce/refunds/out-refund-no/{$out_refund_no}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询垫付回补结果(退款)
* @param string $refund_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryRefundsReturnAdvance($refund_id)
{
$pathinfo = "/v3/ecommerce/refunds/{$refund_id}/return-advance";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询垫付回补结果(退款)
* @param string $refund_id
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function refundsReturnAdvance($refund_id, $data)
{
$pathinfo = "/v3/ecommerce/refunds/{$refund_id}/return-advance";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询二级商户账户实时余额API(余额查询)
* @param string $sub_mchid
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function fundBalance($sub_mchid)
{
$pathinfo = "/v3/ecommerce/fund/balance/{$sub_mchid}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询二级商户账户日终余额API(余额查询)
* @param string $sub_mchid
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function fundEnddayBalance($sub_mchid)
{
$pathinfo = "/v3/ecommerce/fund/enddaybalance/{$sub_mchid}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询收付通平台账户实时余额API(余额查询)
* @param string $account_type
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function merchantFundBalance($account_type)
{
$pathinfo = "/v3/merchant/fund/balance/{$account_type}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询收付通平台账户日终余额API(余额查询)
* @param string $account_type
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function merchantEnddayBalance($account_type)
{
$pathinfo = "/v3/merchant/fund/enddaybalance/{$account_type}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 二级商户预约提现(商户提现)
* @param array $data POST请求参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function fundWithdraw($data)
{
$pathinfo = "/v3/ecommerce/fund/withdraw";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 二级商户查询预约提现状态(根据商户预约提现单号查询)(商户提现)
* @param string $out_request_no
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryFundWithdrawByNo($out_request_no)
{
$pathinfo = "/v3/ecommerce/fund/withdraw/out-request-no/{$out_request_no}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 二级商户查询预约提现状态(根据微信支付预约提现单号查询)(商户提现)
* @param string $withdraw_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryFundWithdrawById($withdraw_id)
{
$pathinfo = "/v3/ecommerce/fund/withdraw/{$withdraw_id}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 收付通平台预约提现(商户提现)
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function merchantFundWithdraw($data)
{
$pathinfo = "/v3/merchant/fund/withdraw";
return $this->doRequest('POST', $pathinfo, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 收付通平台查询预约提现状态(根据商户预约提现单号查询)(商户提现)
* @param string $out_request_no
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryMerchantFundWithdrawByNo($out_request_no)
{
$pathinfo = "/v3/merchant/fund/withdraw/out-request-no/{$out_request_no}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 收付通平台查询预约提现状态(根据微信支付预约提现单号查询)(商户提现)
* @param string $withdraw_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function queryMerchantFundWithdrawById($withdraw_id)
{
$pathinfo = "/v3/merchant/fund/withdraw/withdraw-id/{$withdraw_id}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 按日下载提现异常文件(商户提现)
* @param $bill_type
* @param array $param
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function fundWithdrawBill($bill_type, $param = [])
{
$pathinfo = "/v3/merchant/fund/withdraw/bill-type/{$bill_type}?" . http_build_query($param);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 申请交易账单(下载账单)
* @param $bill_type
* @param array $param
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function tradeBill($bill_type, $param = [])
{
$pathinfo = "/v3/bill/tradebill?" . http_build_query($param);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 申请资金账单(下载账单)
* @param $bill_type
* @param array $param
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function fundFlowBill($bill_type, $param = [])
{
$pathinfo = "/v3/bill/fundflowbill?" . http_build_query($param);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 申请分账账单(下载账单)
* @param string $bill_type
* @param array $param
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function profitsharingBill($bill_type, $param = [])
{
$pathinfo = "/v3/profitsharing/bills?" . http_build_query($param);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 申请二级商户资金账单(下载账单)
* @param string $bill_type
* @param array $param
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function subFundFlowBill($bill_type, $param = [])
{
$pathinfo = "/v3/ecommerce/bill/fundflowbill?" . http_build_query($param);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询支持个人业务的银行列表
* @param int $offset
* @param int $limit
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function personalBanking($offset, $limit)
{
$pathinfo = "/v3/capital/capitallhh/banks/personal-banking?" . http_build_query(['offset' => $offset, 'limit' => $limit]);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询省份列表
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function provinces()
{
$pathinfo = "/v3/capital/capitallhh/areas/provinces";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询城市列表
* @param int $code
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function cities($code)
{
$pathinfo = "/v3/capital/capitallhh/areas/provinces/{$code}/cities";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询支行列表
* @param int $code
* @param $city
* @param $offset
* @param $limit
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function branches($code, $city, $offset, $limit)
{
$pathinfo = "/v3/capital/capitallhh/banks/{$code}/branches?" . http_build_query(['city_code' => $city, 'offset' => $offset, 'limit' => $limit]);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 查询支持对公业务的银行列表
* @param int $offset
* @param int $limit
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function corporateBanking($offset, $limit)
{
$pathinfo = "/v3/capital/capitallhh/banks/corporate-banking?" . http_build_query(['offset' => $offset, 'limit' => $limit]);
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 通过支付预订单ID获取支付参数
* @param string $prepay_id 支付预订单ID
* @param string $type 类型
* @return array
*/
public function getJsApiParameters($prepay_id, $type = 'jsapi')
{
// 支付参数签名
$time = strval(time());
$appid = $this->config['appid'];
$nonceStr = Tools::createNoncestr();
if ($type === 'app') {
$sign = $this->signBuild(join("\n", [$appid, $time, $nonceStr, $prepay_id, '']));
return ['partnerId' => $this->config['mch_id'], 'prepayId' => $prepay_id, 'package' => 'Sign=WXPay', 'nonceStr' => $nonceStr, 'timeStamp' => $time, 'sign' => $sign];
} elseif ($type === 'jsapi') {
$sign = $this->signBuild(join("\n", [$appid, $time, $nonceStr, "prepay_id={$prepay_id}", '']));
return ['appId' => $appid, 'timestamp' => $time, 'timeStamp' => $time, 'nonceStr' => $nonceStr, 'package' => "prepay_id={$prepay_id}", 'signType' => 'RSA', 'paySign' => $sign];
} else {
return [];
}
}
}

View File

@ -31,13 +31,12 @@ class ProfitSharing extends BasicWePay
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function create($options)
public function create(array $options)
{
$options['appid'] = $this->config['appid'];
return $this->doRequest('POST', '/v3/profitsharing/orders', json_encode($options, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询分账结果
* @param string $outOrderNo 商户分账单号
@ -57,7 +56,7 @@ class ProfitSharing extends BasicWePay
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function unfreeze($options)
public function unfreeze(array $options)
{
return $this->doRequest('POST', '/v3/profitsharing/orders/unfreeze', json_encode($options, JSON_UNESCAPED_UNICODE), true);
}
@ -78,11 +77,15 @@ class ProfitSharing extends BasicWePay
* 添加分账接收方
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function addReceiver($options)
public function addReceiver(array $options)
{
$options['appid'] = $this->config['appid'];
if (isset($options['name'])) {
$options['name'] = $this->rsaEncode($options['name']);
}
return $this->doRequest('POST', "/v3/profitsharing/receivers/add", json_encode($options, JSON_UNESCAPED_UNICODE), true);
}
@ -92,9 +95,21 @@ class ProfitSharing extends BasicWePay
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function deleteReceiver($options)
public function deleteReceiver(array $options)
{
$options['appid'] = $this->config['appid'];
return $this->doRequest('POST', "/v3/profitsharing/receivers/delete", json_encode($options, JSON_UNESCAPED_UNICODE), true);
}
/**
* 请求分账回退
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function backspace(array $options)
{
$options['appid'] = $this->config['appid'];
return $this->doRequest('POST', "/v3/profitsharing/return-orders", json_encode($options, JSON_UNESCAPED_UNICODE), true);
}
}

View File

@ -42,12 +42,12 @@ class Transfers extends BasicWePay
foreach ($body['transfer_detail_list'] as &$item) if (isset($item['user_name'])) {
$item['user_name'] = $this->rsaEncode($item['user_name']);
}
}
if (empty($body['total_num'])) {
$body['total_num'] = count($body['transfer_detail_list']);
}
if (empty($body['total_amount'])) {
$body['total_amount'] = array_sum(array_column($body['transfer_detail_list'], 'transfer_amount'));
if (empty($body['total_num'])) {
$body['total_num'] = count($body['transfer_detail_list']);
}
if (empty($body['total_amount'])) {
$body['total_amount'] = array_sum(array_column($body['transfer_detail_list'], 'transfer_amount'));
}
}
return $this->doRequest('POST', '/v3/transfer/batches', json_encode($body, JSON_UNESCAPED_UNICODE), true);
}

View File

@ -14,21 +14,31 @@
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
// 配置缓存处理函数
//\WeChat\Contracts\Tools::$cache_callable = [
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// return $value;
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// return $value;
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// return true;
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
//];
// ];
return [
'token' => 'test',

View File

@ -26,6 +26,32 @@ $certPrivate = <<<CERT
-----END PRIVATE KEY-----
CERT;
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// return $value;
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// return $value;
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// return true;
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];
return [
// 可选公众号APPID
'appid' => '',

View File

@ -14,7 +14,34 @@
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// return $value;
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// return $value;
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// return true;
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];
return [
'appid' => '', // 企业ID
'appsecret' => '', // 应用的凭证密钥
'appid' => '', // 企业ID
'appsecret' => '', // 应用的凭证密钥
'cache_path' => '', // 配置缓存目录
];

View File

@ -19,7 +19,7 @@
"WeChatDeveloper"
],
"require": {
"php": ">=5.5",
"php": ">=5.4",
"ext-xml": "*",
"ext-json": "*",
"ext-curl": "*",
@ -30,6 +30,9 @@
"ext-simplexml": "*"
},
"autoload": {
"files": [
"helper.php"
],
"classmap": [
"We.php"
],

25
helper.php Normal file
View File

@ -0,0 +1,25 @@
<?php
if (!function_exists('array_column')) {
/**
* PHP 版本兼容函数
* @param $input
* @param $columnKey
* @param $indexKey
* @return array
*/
function array_column($input, $columnKey, $indexKey = null)
{
$result = array();
foreach ($input as $row) {
if (isset($row[$columnKey])) {
if ($indexKey !== null && isset($row[$indexKey])) {
$result[$row[$indexKey]] = $row[$columnKey];
} else {
$result[] = $row[$columnKey];
}
}
}
return $result;
}
}

View File

@ -14,6 +14,8 @@
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
include_once __DIR__ . '/helper.php';
spl_autoload_register(function ($classname) {
$pathname = __DIR__ . DIRECTORY_SEPARATOR;
$filename = str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';

View File

@ -43,8 +43,11 @@ WeChatDeveloper 是基于官方接口封装,在做微信开发前,必需先
----
WeChatDeveloper 为开源项目,允许把它用于任何地方,不受任何约束,欢迎 fork 项目。
* Gitee 托管地址https://gitee.com/zoujingli/WeChatDeveloper
* GitHub 托管地址https://github.com/zoujingli/WeChatDeveloper
我们的代码仓库已移至 **Github**,而 **Gitee****Gitcode** 则仅作为国内镜像仓库,方便广大开发者获取和使用。若想提交 **PR****ISSUE** 请在 [WeChatDeveloper](https://github.com/zoujingli/WeChatDeveloper) 仓库进行操作,如果在其他仓库操作或提交问题将无法处理!
* Gitee 仓库地址https://gitee.com/zoujingli/WeChatDeveloper
* GitHub 仓库地址https://github.com/zoujingli/WeChatDeveloper
* GitCode 仓库地址https://gitcode.com/ThinkAdmin/WeChatDeveloper
文件说明(后续会根据官方文档增加文件)
----
@ -114,6 +117,32 @@ include "您的目录/WeChatDeveloper/include.php";
2.1 接口实例所需参数
```php
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// return $value;
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// return $value;
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// return true;
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];
$config = [
'token' => 'test',
'appid' => 'wx60a43dd8161666d4',