Compare commits

...

329 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
邹景立
868d6dcb7f fix: 限定最低 php 版本为 5.5 2024-08-04 23:02:08 +08:00
邹景立
c102bfa331 fix: 微信 V3 提现增加自动统计金额 2024-08-04 23:01:24 +08:00
邹景立
d05f53e548 fix: 增加 GithubActions 配置脚本 2024-08-04 23:01:00 +08:00
邹景立
92fda9036b httpPostForJson 增加 options 请求参数 2024-03-06 17:09:37 +08:00
邹景立
812aae37ff 修改版本号 2024-01-16 21:13:59 +08:00
邹景立
162415b27c 修正一处理赋值 2024-01-16 21:13:35 +08:00
邹景立
cd5ff0228e 标准化参数 2024-01-02 17:59:49 +08:00
邹景立
4e0e9d79cc 优化接口调用,标准化请求 2024-01-02 17:57:37 +08:00
邹景立
78b0393048 修改参数 2024-01-02 17:12:06 +08:00
邹景立
b5e7d17484 优化小程序二维码SDK参数 2024-01-02 17:07:55 +08:00
邹景立
f8f0adb3f1 批量修改注释 2023-12-31 21:09:48 +08:00
邹景立
4f96423812 修改版本号 2023-12-31 15:05:13 +08:00
邹景立
931a6a3a85 增加小程序发货管理 2023-12-31 15:04:56 +08:00
邹景立
b14ce9c381 修改版本号 2023-12-28 21:45:38 +08:00
邹景立
4aa98a58a6 修正ORC识别调用 2023-12-28 21:40:51 +08:00
邹景立
b799247cd2 修改版本号 2023-12-18 14:24:51 +08:00
邹景立
7f0a4ed890 修改小程序二维码 2023-12-18 14:24:26 +08:00
邹景立
42933f79b2 修改调用注释 2023-11-06 22:56:08 +08:00
邹景立
fdb9b63deb 修改 echo 注释 2023-11-06 22:45:40 +08:00
邹景立
ef32690703 修改回显方式 2023-11-06 22:41:55 +08:00
邹景立
ce70444b6c 去除 Exit 函数 2023-11-06 09:09:29 +08:00
邹景立
9becf988c9 修改版本号 2023-10-10 17:40:17 +08:00
Anyon
5130bac7c5
!12 v2微信分账增加代码提示注释
Merge pull request !12 from Innovation/master
2023-09-28 13:48:41 +00:00
Anyon
59c4144f1f
!13 update WeChat/Media.php.
Merge pull request !13 from pkkgu/N/A
2023-09-28 13:48:28 +00:00
pkkgu
649bda174c
update WeChat/Media.php.
获取临时和永久素材时,可以直接返回组装后的素材链接。(方便将链接提交给第三方处理附件,已知七牛和讯飞可以直接处理微信的素材链接)

Signed-off-by: pkkgu <910111100@qq.com>
2023-09-27 13:07:15 +00:00
Innovation
2708e8d94a v2微信分账增加代码提示注释 2023-09-27 11:09:54 +08:00
Anyon
f5123f899e
!11 添加分账
Merge pull request !11 from Innovation/master
2023-09-26 11:50:29 +00:00
Innovation
10c4efc584 微信分账 2023-09-25 20:36:55 +08:00
邹景立
2b49fc78a3 修改依赖配置 2023-09-19 13:51:54 +08:00
邹景立
c361075864 同步更新退款通知处理 2023-07-13 19:59:18 +08:00
邹景立
6fabf8a9e3 fix 更新小程序模板接口
#I7IJ55 更新小程序模板接口
2023-07-05 16:21:57 +08:00
邹景立
9eac291f5c 修改微信V3支付参数兼容 2023-06-27 15:50:58 +08:00
邹景立
e72641a5ae 修改版本号 2023-06-19 14:20:18 +08:00
邹景立
cc460dbdba Update BasicWePay.php 2023-06-19 14:17:22 +08:00
邹景立
a629b2d676 Update BasicWePay.php 2023-06-19 14:11:56 +08:00
邹景立
b84cc6d54f Update BasicWePay.php 2023-06-19 14:04:13 +08:00
邹景立
9f236c374c 增加批量打款测试案例 2023-06-19 14:02:21 +08:00
邹景立
b9c4823486 修改平台证书机制
#
2023-06-19 13:49:47 +08:00
邹景立
683eb10ebd 修改部分接口TOKEN问题 2023-05-23 16:55:02 +08:00
邹景立
8f7758975c Update pay-refund-create.php 2023-05-16 10:18:33 +08:00
邹景立
8e532f25c7 修改测试 2023-05-16 10:16:16 +08:00
邹景立
eca01d957b 修改退款接口 2023-05-16 10:10:08 +08:00
邹景立
af7ea76eae 返回结果不验签
因为老是有人把支付宝公钥搞错
2023-05-07 14:11:34 +08:00
邹景立
940cdf8abf 修改支付宝支付签名问题 2023-05-07 14:08:00 +08:00
邹景立
5db97a1d90 Update readme.md 2023-05-06 19:16:41 +08:00
邹景立
966fd08bf9 小程序二维码,增加其他参数传入
#I5OUBO
2023-05-06 15:27:38 +08:00
邹景立
7dfe73b646 修改配置 2023-05-06 15:22:24 +08:00
邹景立
187690f40e Update alipay.php 2023-05-06 15:09:02 +08:00
邹景立
6cb56ec0ed Update BasicAliPay.php 2023-05-06 14:55:57 +08:00
邹景立
98ffdf2575 修改支付宝参数配置 2023-05-06 14:55:05 +08:00
邹景立
2fdb22b1ef Update alipay.php 2023-05-06 14:50:36 +08:00
邹景立
dc15ae7732 修改支付宝参数配置 2023-05-06 14:49:31 +08:00
邹景立
5f3801d100 Update readme.md 2023-05-06 13:44:39 +08:00
邹景立
15b1555d74 修正 Qrc 支付问题 2023-05-06 13:40:24 +08:00
邹景立
164c45e3a8 Update readme.md 2023-05-06 13:37:23 +08:00
邹景立
af1051ce6f Update Refund.php 2023-05-05 21:58:03 +08:00
邹景立
1f73aad17d 退款通知迁入 2023-05-05 21:56:45 +08:00
邹景立
32382bb75b fix 兼容内存框架
在不能使用 file_get_contents('php://input') 时,
使用 $GLOBALS['HTTP_RAW_POST_DATA'] 传值。

#I5TXCL
2023-05-05 21:26:53 +08:00
邹景立
685617267f 增加 无 headers 处理 2023-05-04 22:58:15 +08:00
邹景立
c806ba514a 修改证书配置 2023-05-02 23:39:44 +08:00
邹景立
4d77813064 修改支付宝支付参数 2023-05-02 22:56:55 +08:00
邹景立
0595f9bcb2 修改接口 2023-05-02 22:54:26 +08:00
邹景立
c5ff92f778 企业打款增加大于2000的RSA名称加密 2023-05-02 21:17:17 +08:00
邹景立
dc29ee61a7 增加订单创建异常输出 2023-05-02 21:16:50 +08:00
邹景立
196edc08a2 #I6K2RH 增加 RSA 加密 2023-05-02 20:56:08 +08:00
邹景立
e9479cb19b 标识 Refund 过时 2023-05-02 10:41:47 +08:00
邹景立
1ffa938429 修改接口地址计算 2023-04-28 20:07:04 +08:00
邹景立
ac63302119 修改账单下载 2023-04-28 20:05:23 +08:00
邹景立
8630e29773 增加运行时缓存路径配置 2023-04-28 19:58:55 +08:00
邹景立
53f3dce3dd 完善更多直连商户接口 2023-04-28 19:45:43 +08:00
邹景立
200f14dba9 修改支付参数,增加证书序号配置(可选) 2023-04-28 19:06:35 +08:00
Anyon
aede81dce3
!8 修复分账错误
Merge pull request !8 from 承诺/master
2023-03-28 13:57:08 +00:00
承诺
c77d788f27
修复分账错误
Signed-off-by: 承诺 <1322522027@qq.com>
2023-03-28 10:17:22 +00:00
Anyon
d27b1a451e
!7 增加分账
Merge pull request !7 from Anyon/cherry-pick-1679379499
2023-03-21 06:19:55 +00:00
承诺
18fac9288a fixed b523868 from https://gitee.com/zoujingli/WeChatDeveloper/pulls/5
添加商家分账

Signed-off-by: 承诺 <1322522027@qq.com>
2023-03-21 06:18:19 +00:00
邹景立
fc3edaa6ae Update composer.json 2023-03-11 10:12:10 +08:00
邹景立
40dfd76a99 Update readme.md 2023-02-26 23:42:16 +08:00
邹景立
7b97910d13 批量更新注释,更新描述 2023-02-26 23:38:20 +08:00
邹景立
fbd573d2bd Update readme.md 2023-02-26 23:23:31 +08:00
邹景立
6b8674627e Update readme.md 2023-02-26 23:22:06 +08:00
邹景立
251841630e
Merge pull request #82 from humengcn/master
把Prpcrypt文件拆为三个Class文件
2023-02-04 20:39:34 +08:00
huemng
262b7eb0e2 把Prpcrypt文件拆为三个Class文件 2023-01-31 16:26:20 +08:00
邹景立
471863eac5
Merge pull request #81 from imzhi/v3-transfer
增加v3转账查询明细单
2022-12-31 00:28:22 +08:00
imzhi
355ac5e0c0 增加v3转账查询明细单 2022-12-27 09:15:36 +08:00
邹景立
6071c49d51 增加微信V3打款 2022-12-13 11:32:04 +08:00
邹景立
f4b0caee32 修改v2支付demo 2022-11-21 19:08:24 +08:00
邹景立
a913c1e4f1 修改支付描述 2022-11-21 18:52:12 +08:00
邹景立
69d4cf8e1b 增加支付案例 2022-11-21 18:48:35 +08:00
邹景立
48245c7a01 修改测试文件 2022-11-18 18:13:23 +08:00
邹景立
18e7200a69 修改测试证书 2022-11-18 18:12:50 +08:00
邹景立
005181c252 Update readme.md 2022-11-14 17:40:38 +08:00
邹景立
32bae5badc 修改文档说明 2022-11-12 18:27:16 +08:00
邹景立
1d453606d3 修改小程序兼容 2022-11-12 17:53:28 +08:00
邹景立
a18961eb39
Merge pull request #80 from voilaf/master
WechatPayV3和Alipay支付回调应支持外部传入参数
2022-11-05 11:07:41 +08:00
voilaf
bcf7cceb91 WechatPayV3和Alipay支付回调应支持外部传入参数 2022-11-02 15:47:25 +08:00
邹景立
14932d9095 标准化文档注释,方便 IDE 识别 2022-09-22 16:01:08 +08:00
邹景立
048bef14b7 修改注释 2022-09-22 15:44:31 +08:00
邹景立
8ad6e828a6 修改注释,授权协议 2022-09-05 13:33:13 +08:00
邹景立
7fec514e9e 修改注释 2022-09-05 13:27:36 +08:00
邹景立
db9373b4d3
Merge pull request #78 from big-dream/patch-1
如果参数的值为空不参与签名
2022-09-05 13:13:16 +08:00
邹景立
147bcf7119 #73 增加 callback 处理 2022-09-05 13:08:53 +08:00
蒋文健
c95d20fb4c
如果参数的值为空不参与签名 2022-08-27 18:43:24 +08:00
Anyon
e061f4e374
!4 update WeChat/Qrcode.php.
Merge pull request !4 from pkkgu/N/A
2022-08-22 08:21:36 +00:00
pkkgu
634278d1ae
update WeChat/Qrcode.php.
通过ticket换取二维码(ticket应该加urlencode)否则某些情况下可能换取失败



Signed-off-by: pkkgu <910111100@qq.com>
2022-08-22 07:06:33 +00:00
Anyon
7a428869df 增加静态加载V3Pay 2022-07-26 11:56:32 +08:00
Anyon
a598aaa2b8 兼容php8语法 2022-05-25 11:48:22 +08:00
Anyon
cfe3e83798 修改版本号 2022-04-26 11:02:29 +08:00
Anyon
8775e7b346 修改注释 2022-04-18 14:03:14 +08:00
Anyon
6f978d1dfd Update Tools.php 2022-04-18 14:01:14 +08:00
Anyon
34412f58fb 移除小程序接口重复注入的问题 2022-04-06 17:37:27 +08:00
邹景立
7e463a0c80
Merge pull request #72 from taochangle/patch-5
修复上传草稿库bug
2022-02-18 12:57:13 +08:00
陶欣
5400257395
修复上传草稿库bug 2022-02-17 19:13:35 +08:00
邹景立
ee2f830452
Merge pull request #71 from taochangle/patch-4
微信发布能力、微信草稿箱接口添加
2021-12-26 16:46:27 +08:00
邹景立
b6c6ace829
Merge pull request #70 from taochangle/patch-2
微信草稿箱管理
2021-12-26 16:46:04 +08:00
邹景立
a9ac77c30d
Merge pull request #69 from taochangle/patch-3
微信草稿箱、发布能力接口添加
2021-12-26 16:45:49 +08:00
邹景立
6c8a3515c2
Merge pull request #68 from taochangle/patch-1
发布能力
2021-12-26 16:45:19 +08:00
陶欣
05cec3703d
微信发布能力、微信草稿箱接口添加 2021-12-25 18:34:14 +08:00
陶欣
d77ee9bbcc
微信草稿箱、发布能力接口添加 2021-12-25 18:30:56 +08:00
陶欣
4c30f1d2c6
微信草稿箱管理 2021-12-25 18:29:53 +08:00
陶欣
cdb867e626
发布能力 2021-12-25 18:29:15 +08:00
Anyon
686eb9d438 Update Scheme.php 2021-12-09 11:49:54 +08:00
Anyon
fb4b0e629b Update Scheme.php 2021-12-09 11:46:47 +08:00
Anyon
3477bfca71 增加小程序URL-LINK 2021-12-09 11:45:34 +08:00
Anyon
5409c53f07 Update Scheme.php 2021-12-09 11:05:29 +08:00
Anyon
f61067ce5a 增加小程序 URL-Scheme 2021-12-09 10:37:31 +08:00
邹景立
cf2037dbac Update Tools.php 2021-11-11 14:24:28 +08:00
邹景立
9416930902 兼容PHP8 2021-11-11 14:20:15 +08:00
邹景立
e392007c6b Update alipay.php 2021-11-11 12:24:05 +08:00
邹景立
32f163af0c #I4FTJK 修改签名方式 2021-11-02 14:14:18 +08:00
邹景立
d461761c08
Merge pull request #65 from humengcn/master
初始化指定jsApiList
2021-10-26 10:33:42 +08:00
humeng93
35c7b12e02 初始化指定jsApiList 2021-10-25 22:08:29 +08:00
邹景立
82ac3c977e Update We.php 2021-09-29 11:18:27 +08:00
邹景立
94d515587d #64 2021-09-28 10:52:01 +08:00
邹景立
cce155088f Update We.php 2021-09-26 10:09:39 +08:00
邹景立
58478f9baa #63
修改内容检查
2021-09-26 10:03:44 +08:00
邹景立
f8bac656d5 修改文件注释 2021-09-15 23:47:01 +08:00
邹景立
9c01d4301a 修改刷卡支付授权码查询参数 2021-07-13 10:07:39 +08:00
邹景立
a4d57428ba 修改代码注释 2021-05-19 14:29:16 +08:00
邹景立
0cf699c725 Update We.php 2021-05-19 14:25:20 +08:00
邹景立
84f0a04aa3 调整V3支付签名及Script缓存时间 2021-05-19 14:25:06 +08:00
邹景立
946a4c40ab
Merge pull request #62 from kentwangit/patch-1
Update Order.php
2021-05-19 14:15:06 +08:00
kentwangit
2f1128b923
Update composer.json 2021-05-19 11:35:03 +08:00
kentwangit
d32b3ecd88
Update Order.php
微信要求:
签名串一共有四行,每一行为一个参数。行尾以\n(换行符,ASCII编码值为0x0A)结束,包括最后一行。
如果最后一行没有加\n,前端调起支付时会提签名错误。
2021-04-29 16:18:22 +08:00
邹景立
4ba213dcea 修改微信海关接口 2021-04-15 11:16:50 +08:00
邹景立
7197e5296e 修改微信v3支付参数描述 2021-04-07 09:43:49 +08:00
邹景立
049de7d325 Update BasicWePay.php 2021-03-23 18:16:40 +08:00
邹景立
5d8955a41d Update Custom.php 2021-03-23 18:14:20 +08:00
邹景立
0b086a29d7 Update Custom.php 2021-03-23 18:12:26 +08:00
邹景立
60540547d1 增加海关 2021-03-23 18:11:48 +08:00
邹景立
463c677cfd v1.2.28 2021-03-09 18:04:53 +08:00
邹景立
6d3c22b85c Update composer.json 2021-03-09 18:00:42 +08:00
邹景立
c919c8c08c 修改项目描述 2021-01-12 14:22:03 +08:00
Anyon
94de6626f1 修复退款通知处理 2020-12-24 17:44:04 +08:00
Anyon
0646ff3bb9 修改V3接口参数 2020-12-24 17:32:13 +08:00
Anyon
0c01bd0761 支付退款通知异常处理 2020-12-24 16:40:19 +08:00
Anyon
d5dfc08aee 修改退款通知及版本号 2020-12-24 16:34:42 +08:00
Anyon
c7bc47a451 Update Order.php 2020-12-21 15:46:33 +08:00
Anyon
25b47108ac Update BasicWePay.php 2020-12-18 10:24:46 +08:00
Anyon
d657658c93 修改静态加载描述 2020-12-18 10:17:36 +08:00
Anyon
29a9caa1eb 调整支付通知处理 2020-12-18 10:09:54 +08:00
Anyon
a687b005d5 调整支付通知处理 2020-12-18 10:08:10 +08:00
Anyon
f726a62718 修改注释 2020-12-17 17:17:40 +08:00
Anyon
eb5c4f6ab5 修改文档描述 2020-12-17 17:02:42 +08:00
Anyon
4be6d206d9 增加V3接口配置 2020-12-17 17:00:08 +08:00
Anyon
974f18ebf7 修改微信v3支付 2020-12-17 15:48:48 +08:00
Anyon
a4c94eed34 增加微信V3接口支持 2020-12-17 15:31:29 +08:00
Anyon
d4a93b6d50 修改基础代码 2020-12-11 13:56:20 +08:00
Anyon
5ecafcd810 Update We.php 2020-09-13 14:01:11 +08:00
Anyon
3c22eeb493 #14 增加授权code参数传递 2020-09-13 13:58:43 +08:00
Anyon
0d8e889a47 默认去除 Emoji 表情处理,请把数据库转为 utf8mb4 2020-08-31 11:44:38 +08:00
Anyon
6fcb650490 修改文件注释 2020-08-19 16:52:11 +08:00
Anyon
9b9d3b01ca 增加企业号支持 2020-08-19 16:51:04 +08:00
邹景立
2e5ca0d48f
Update We.php
修改组件版本
2020-08-16 15:01:12 +08:00
邹景立
fe3b5910ba
Update Tools.php
修改接口兼容
2020-08-16 14:59:53 +08:00
Anyon
2308c9fb32 修改支付宝支付测试案例 2020-07-30 17:41:37 +08:00
邹景立
8f07eba9a9
Merge pull request #49 from qfz9527/master
修改小程序接口请求类型
2020-07-30 17:32:10 +08:00
刘观
34c971344e 修改小程序接口请求类型 2020-07-30 15:11:50 +08:00
liu guan
7c6b53a229
Merge pull request #2 from zoujingli/master
pull
2020-07-30 15:01:38 +08:00
Anyon
f070dd076a 修改json请求方式 2020-07-20 14:55:26 +08:00
Anyon
7eb7f6a2d8 修改小程序支持 2020-07-04 15:24:41 +08:00
Anyon
59dc89244e 修改AccessToken处理 2020-05-21 10:40:44 +08:00
Anyon
5cf008c374 修改xml3arr 2020-04-26 11:22:09 +08:00
Anyon
656223cd2a Update Tools.php 2020-04-26 11:18:55 +08:00
Anyon
0b7ec9fff9 Update Tools.php 2020-04-26 11:13:59 +08:00
Anyon
90b5b091a2 Update Tools.php 2020-04-26 11:12:37 +08:00
Anyon
d42e8836f7 增加xml解析方式 2020-04-26 11:08:57 +08:00
Anyon
e8161351be Update We.php 2020-03-14 15:00:10 +08:00
Anyon
9afb0a29c6 增加小程序直播接口 2020-03-14 14:58:18 +08:00
Anyon
f4ae17165a Update Trade.php 2020-03-12 09:51:56 +08:00
Anyon
e3254d4e6c Update Trade.php 2020-03-11 18:40:01 +08:00
Anyon
72749aefe2 Update Trade.php 2020-03-11 18:39:09 +08:00
Anyon
17ca010939 Create Trade.php 2020-03-11 18:38:22 +08:00
Anyon
c30e880bf7 Update BasicAliPay.php 2020-03-11 17:50:03 +08:00
Anyon
8bfd9f9a69 Update alipay.php 2020-03-11 10:05:10 +08:00
Anyon
3268e19c61 Update BasicAliPay.php 2020-03-11 10:04:31 +08:00
Anyon
9dbabfe89e 更新支付资金接口 2020-03-11 09:47:17 +08:00
Anyon
a94f30edff Update composer.json 2020-03-06 15:15:53 +08:00
Anyon
73da26babd Update composer.json 2020-03-06 15:15:20 +08:00
Anyon
df25396ae2 Update readme.md 2020-03-06 15:05:34 +08:00
Anyon
d28fde141b Update alipay-refund.php 2020-03-06 15:03:59 +08:00
Anyon
58d3ef5384 Update include.php 2020-03-06 15:00:42 +08:00
Anyon
aaffc0a149 Update We.php 2020-03-06 14:58:57 +08:00
Anyon
372c422ab9 Update We.php 2020-03-06 14:58:15 +08:00
Anyon
7eb32f1451 增加小程序运维中心接口 2020-03-06 14:53:08 +08:00
Anyon
e9f2605f92 增加小程序搜索 2020-03-06 14:50:36 +08:00
Anyon
d4f1d7acda Create Search.php 2020-03-06 14:44:23 +08:00
Anyon
3a24f257ba 增加局导购助手接口 2020-03-06 14:42:04 +08:00
Anyon
98f6e82311 Update Transfer.php 2020-03-03 09:38:07 +08:00
Anyon
418e132e3e 增加新版支付打款接口 2020-03-02 19:08:34 +08:00
邹景立
01fa1479e8
Merge pull request #38 from qfz9527/master
添加订阅消息相关接口
2020-01-04 16:51:50 +08:00
刘观
cc826c4d6a 添加订阅消息相关接口 2019-12-26 15:10:51 +08:00
liu guan
038dde16ac
Merge pull request #1 from zoujingli/master
pull
2019-12-25 15:21:24 +08:00
Anyon
4b81e72cff 修正 pay 退款调用别名 2019-11-25 18:40:50 +08:00
Anyon
39d53dd910 修改静态缓存变量 2019-11-05 10:35:27 +08:00
Anyon
63c2ef5e68 增加微信付款码支付及静态实例调用
一、增加刷卡支付接口 #30
二、增加静态实例调用
2019-11-05 10:21:02 +08:00
Anyon
5fdc20c4a4 [更新]修正获取用户资料不能指定语言的问题 2019-10-29 17:14:09 +08:00
Anyon
5789420f58 Update We.php 2019-09-16 13:20:21 +08:00
Anyon
7c2dfd4c5f [更新]完善小程序新服务接口 2019-09-16 13:18:54 +08:00
Anyon
67dcd1329e [更新]完善小程序新服务接口 2019-09-16 13:17:35 +08:00
Anyon
5719fa2dd6 [更新]完善小程序服务端接口 2019-09-11 19:41:07 +08:00
Anyon
d5722887cc Update readme.md 2019-07-08 15:10:14 +08:00
Anyon
9464d20af4 [更新]获取二进制资源接口增加重试 2019-05-16 10:17:20 +08:00
Anyon
d6b86979ac Update MyCurlFile.php 2019-04-23 16:02:06 +08:00
Anyon
b4a905a618 Merge branch 'master' of https://github.com/zoujingli/WeChatDeveloper 2019-04-23 15:52:27 +08:00
Anyon
29b1d1f373 [更新]增加缓存文件写入配置 2019-04-23 15:52:21 +08:00
邹景立
edef5e6158
Merge pull request #24 from rootrl/master
Modify  first result_code to return_code
2019-04-11 12:00:39 +08:00
Rootrl
83506ac24c
Modify first result_code to return_code 2019-04-10 15:26:04 +08:00
Anyon
f204629dc5 [更新]添加Emoji表情支持测试 2019-04-09 11:10:57 +08:00
Anyon
543d4a84dc Update readme.md 2019-04-04 13:20:54 +08:00
Anyon
f68a378fc9 [更新]修改小程序二维码生成参数 2019-03-30 15:30:45 +08:00
Anyon
103488a1cd [更新]Emoji表情处理 2019-03-27 15:01:49 +08:00
Anyon
5032d02069 [更新]增加微信红包发放 2019-02-25 10:15:38 +08:00
Anyon
06ee3506a8 [更新]修改内容接收解析 2019-02-18 15:47:07 +08:00
Anyon
3846f79b6d Update We.php 2019-01-14 14:05:41 +08:00
Anyon
5938b344f4 Update We.php 2019-01-14 14:04:41 +08:00
Anyon
def818b7df [更新]去除支付宝返回结果签名验证 2019-01-12 19:40:04 +08:00
Anyon
79126e15ba [更新]修改微信jssdk授权方法 2019-01-07 14:53:11 +08:00
Anyon
401042c4f1 [更新]增加RSA签名支持 2018-12-25 10:15:33 +08:00
Anyon
c0ce839061 [更新]修改公钥注释 2018-12-25 09:48:22 +08:00
Anyon
9e11720287 [更新]修改兼容代码 2018-12-19 15:58:04 +08:00
Anyon
9587b125b8 Update BasicPushEvent.php 2018-12-14 16:36:16 +08:00
Anyon
7fab512e05 Update Tools.php 2018-12-14 15:13:07 +08:00
Anyon
63458d810f [更新]修正微信App支持 2018-12-12 17:59:07 +08:00
Anyon
365b012ec6 [更新]增加app支付参数获取 2018-12-12 14:52:27 +08:00
Anyon
fbf73b5ca4 Update Tools.php 2018-12-05 17:06:38 +08:00
Anyon
018918d342 [更新]增加MyCurlFile文件类型 2018-12-05 16:58:37 +08:00
Anyon
f4c08f4c81 [更新]增加自定义CURLFILE类(方便跨服务器文件传输) 2018-12-05 15:25:42 +08:00
邹景立
f5926e59fa
Rename README.md to readme.md 2018-11-27 17:32:30 +08:00
Anyon
9ce8dbe0dd [更新]同步jsapi_v.14接口列表 2018-11-26 14:58:35 +08:00
Anyon
16cc729535 [更新]增加部分接口支持 2018-11-26 14:51:58 +08:00
Anyon
009f1eaeb7 Create pay-order-notify.php 2018-11-20 17:49:16 +08:00
Anyon
70b9868852 [更新]微信支付增加获取通知处理返回成功的方法 getNotifySuccessReply 2018-11-20 17:41:20 +08:00
Anyon
c5a9f9e9ff Merge branch 'master' of https://github.com/zoujingli/WeChatDeveloper 2018-11-20 12:47:30 +08:00
Anyon
32931c9a04 Update README.md 2018-11-20 12:47:25 +08:00
邹景立
e6be8222c2 [更新]修改支付宝支付获取支付通知demo #20 2018-11-19 21:44:54 +08:00
邹景立
0c824f2bce [更新]统一使用DataAccess标准赋值 2018-11-19 21:35:36 +08:00
邹景立
5e91d82653 [更新]修改方法注释 #20 2018-11-19 21:28:19 +08:00
邹景立
37c8ab0afe [更新]增加获取支付通知的方法 notify #20 【待测试】 2018-11-19 21:24:17 +08:00
Anyon
7e9ec275be Update README.md 2018-11-13 18:31:49 +08:00
Anyon
c48d497f27 Update README.md 2018-11-13 18:08:37 +08:00
Anyon
9db3744f47 [更新]修改支付宝支付描述 2018-11-13 18:00:47 +08:00
Anyon
02bd663288 Update _test/wechat-user-get.php 2018-11-13 17:46:37 +08:00
Anyon
eea8198d46 Update _test/config.php 2018-11-13 17:45:54 +08:00
Anyon
1defe142e4 Update AliPay/Bill.php 2018-11-13 17:42:55 +08:00
Anyon
ef2ab99cb4 [更新]修改支付宝支付 #19 2018-11-13 17:37:19 +08:00
Anyon
7d02bdc83f Update We.php 2018-11-13 17:17:53 +08:00
Anyon
ace4ce3949 [更新] 增加获取标签下粉丝列表 #2 2018-11-13 17:05:11 +08:00
Anyon
fed0e83057 [更新]修改支付宝支付及项目配置 2018-11-13 09:40:49 +08:00
Anyon
d8a3b73f58 [更新]修改版本号 2018-11-12 22:21:08 +08:00
Anyon
b8fd2795c7 [更新]修改支付宝支付 2018-11-12 22:10:45 +08:00
Anyon
dd9ff2856f [更新]修改支付宝支付 #17 2018-11-12 22:04:06 +08:00
Anyon
f8c8c9d317 [更新]个性支付宝支付 #17 2018-11-12 21:58:40 +08:00
Anyon
42a07c153b Update WeChat/Script.php 2018-11-12 14:37:32 +08:00
Anyon
a2d43b86b0 [更新]修正文件引入文件 2018-11-03 09:20:32 +08:00
Anyon
af3fbadb4a [更新]修改引入文件 2018-11-03 09:13:07 +08:00
Anyon
7e89f110da [更新]修正原支付类名 2018-11-03 09:01:29 +08:00
Anyon
8a323d39c7 [更新]修正原支付类名 2018-11-03 08:58:24 +08:00
Anyon
886b9d8c54 Update We.php 2018-11-01 14:21:55 +08:00
Anyon
05956dd93a Update composer.json 2018-10-30 19:08:56 +08:00
Anyon
afa36b0c66 Update composer.json 2018-10-30 19:08:35 +08:00
Anyon
7a46d4f271 Update composer.json 2018-10-30 19:07:00 +08:00
Anyon
4f02179b04 Update include.php 2018-10-30 19:05:39 +08:00
Anyon
ef02366345 Update WeChat/Contracts/BasicAliPay.php 2018-10-30 18:57:17 +08:00
Anyon
83eba868be [更新]修正函数名称 2018-10-30 18:54:09 +08:00
Anyon
0c1e64f220 Update WeChat/Contracts/BasicAliPay.php 2018-10-30 18:51:08 +08:00
Anyon
210a75b346 Update WeChat/Contracts/BasicAliPay.php 2018-10-30 18:50:23 +08:00
Anyon
bfa43d1506 [更新]调整代码 2018-10-30 18:43:56 +08:00
Anyon
fcb2cdbb08 [更新]调整命名规则 2018-10-30 18:42:47 +08:00
Anyon
3747468813 [更新]移动测试文件 2018-10-30 18:33:43 +08:00
Anyon
631a7f5468 Update README.md 2018-10-30 18:25:23 +08:00
Anyon
0af4f5a909 Update README.md 2018-10-30 18:23:53 +08:00
Anyon
749926df57 Update README.md 2018-10-30 18:22:49 +08:00
Anyon
594645b7c8 Update README.md 2018-10-30 18:21:21 +08:00
Anyon
d609751466 Update README.md 2018-10-30 18:20:31 +08:00
Anyon
777d6c8396 Update README.md 2018-10-30 18:19:39 +08:00
Anyon
21c5b4e3f8 Update README.md 2018-10-30 18:19:12 +08:00
Anyon
5b78438c36 Update README.md 2018-10-30 18:18:20 +08:00
Anyon
92746c6038 [更新]重置支付宝基类 2018-10-30 18:08:00 +08:00
Anyon
faa9b8d0f1 [更新]增加支付宝加载机制 2018-10-30 18:06:47 +08:00
Anyon
1505a043ba [更新]修改支付宝参数 2018-10-30 17:57:58 +08:00
Anyon
9dba6a72a6 [更新]更新支付宝支付代码 2018-10-30 17:51:26 +08:00
Anyon
81a18b8b3a [更新]增加对 支付宝 支持 2018-10-30 17:45:16 +08:00
144 changed files with 10032 additions and 1514 deletions

65
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,65 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
name: Create Release
permissions: write-all
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: npm install -g gen-git-log
- name: Find Last Tag
id: last_tag
run: |
# 获取所有标签,按版本排序(降序)
Tags=$(git tag --list --sort=-version:refname)
# 获取最新的标签(即列表中的第一个)
LATEST_TAG=$(echo "$Tags" | awk 'NR==1 {print $1; exit}')
# 获取倒数第二个标签(如果存在)
if [[ -n "$Tags" ]]; then
# 使用 tail 获取除了最后一个标签之外的所有标签,然后用 head 获取第一个
SECOND_LATEST_TAG=$(echo "$Tags" | tail -n +2 | head -n 1)
else
SECOND_LATEST_TAG=""
fi
# 设置输出变量
echo "::set-output name=tag_last::${LATEST_TAG:-v1.0.0}"
echo "::set-output name=tag_second::${SECOND_LATEST_TAG:-v1.0.0}"
- name: Generate Release Notes
run: |
rm -rf log
newTag=${{ steps.last_tag.outputs.tag_last }}
git-log -m tag -f -S ${{ steps.last_tag.outputs.tag_second }} -v ${newTag#v}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.last_tag.outputs.tag_last }}
release_name: Release ${{ steps.last_tag.outputs.tag_last }}
body_path: log/${{steps.last_tag.outputs.tag_last}}.md
draft: false
prerelease: false

2
.gitignore vendored
View File

@ -4,4 +4,6 @@
/vendor
/Cache
/Test/cert
/nbproject
/composer.lock
/_test/cert

50
AliPay/App.php Normal file
View File

@ -0,0 +1,50 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 支付宝App支付网关
* Class App
* @package AliPay
*/
class App extends BasicAliPay
{
/**
* App constructor.
* @param array $options
*/
public function __construct(array $options)
{
parent::__construct($options);
$this->options->set('method', 'alipay.trade.app.pay');
$this->params->set('product_code', 'QUICK_MSECURITY_PAY');
}
/**
* 创建数据操作
* @param array $options
* @return string
*/
public function apply($options)
{
$this->applyData($options);
return http_build_query($this->options->get());
}
}

49
AliPay/Bill.php Normal file
View File

@ -0,0 +1,49 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 支付宝电子面单下载
* Class Bill
* @package AliPay
*/
class Bill extends BasicAliPay
{
/**
* Bill constructor.
* @param array $options
*/
public function __construct(array $options)
{
parent::__construct($options);
$this->options->set('method', 'alipay.data.dataservice.bill.downloadurl.query');
}
/**
* 创建数据操作
* @param array $options
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function apply($options)
{
return $this->getResult($options);
}
}

50
AliPay/Pos.php Normal file
View File

@ -0,0 +1,50 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 支付宝刷卡支付
* Class Pos
* @package AliPay
*/
class Pos extends BasicAliPay
{
/**
* Pos constructor.
* @param array $options
*/
public function __construct(array $options)
{
parent::__construct($options);
$this->options->set('method', 'alipay.trade.pay');
$this->params->set('product_code', 'FACE_TO_FACE_PAYMENT');
}
/**
* 创建数据操作
* @param array $options
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function apply($options)
{
return $this->getResult($options);
}
}

49
AliPay/Scan.php Normal file
View File

@ -0,0 +1,49 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 支付宝扫码支付
* Class Scan
* @package AliPay
*/
class Scan extends BasicAliPay
{
/**
* Scan constructor.
* @param array $options
*/
public function __construct(array $options)
{
parent::__construct($options);
$this->options->set('method', 'alipay.trade.precreate');
}
/**
* 创建数据操作
* @param array $options
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function apply($options)
{
return $this->getResult($options);
}
}

82
AliPay/Trade.php Normal file
View File

@ -0,0 +1,82 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 支付宝标准接口
* Class Trade
* @package AliPay
*/
class Trade extends BasicAliPay
{
/**
* 设置交易接口地址
* @param string $method
* @return $this
*/
public function setMethod($method)
{
$this->options->set('method', $method);
return $this;
}
/**
* 获取交易接口地址
* @return string
*/
public function getMethod()
{
return $this->options->get('method');
}
/**
* 设置接口公共参数
* @param array $option
* @return Trade
*/
public function setOption($option = [])
{
foreach ($option as $key => $vo) {
$this->options->set($key, $vo);
}
return $this;
}
/**
* 获取接口公共参数
* @return array|string|null
*/
public function getOption()
{
return $this->options->get();
}
/**
* 执行通过接口
* @param array $options
* @return array|boolean
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function apply($options)
{
return $this->getResult($options);
}
}

80
AliPay/Transfer.php Normal file
View File

@ -0,0 +1,80 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 支付宝转账到账户
* Class Transfer
* @package AliPay
*/
class Transfer extends BasicAliPay
{
/**
* 旧版 向指定支付宝账户转账
* @param array $options
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function apply($options)
{
$this->options->set('method', 'alipay.fund.trans.toaccount.transfer');
return $this->getResult($options);
}
/**
* 新版 向指定支付宝账户转账
* @param array $options
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create($options = [])
{
$this->options->set('method', 'alipay.fund.trans.uni.transfer');
return $this->getResult($options);
}
/**
* 新版 转账业务单据查询接口
* @param array $options
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryResult($options = [])
{
$this->options->set('method', 'alipay.fund.trans.common.query');
return $this->getResult($options);
}
/**
* 新版 支付宝资金账户资产查询接口
* @param array $options
* @return array|bool
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryAccount($options = [])
{
$this->options->set('method', 'alipay.fund.account.query');
return $this->getResult($options);
}
}

49
AliPay/Wap.php Normal file
View File

@ -0,0 +1,49 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 手机WAP网站支付支持
* Class Wap
* @package AliPay
*/
class Wap extends BasicAliPay
{
/**
* Wap constructor.
* @param array $options
*/
public function __construct(array $options)
{
parent::__construct($options);
$this->options->set('method', 'alipay.trade.wap.pay');
$this->params->set('product_code', 'QUICK_WAP_WAY');
}
/**
* 创建数据操作
* @param array $options
* @return string
*/
public function apply($options)
{
parent::applyData($options);
return $this->buildPayHtml();
}
}

49
AliPay/Web.php Normal file
View File

@ -0,0 +1,49 @@
<?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 AliPay;
use WeChat\Contracts\BasicAliPay;
/**
* 支付宝网站支付
* Class Web
* @package AliPay
*/
class Web extends BasicAliPay
{
/**
* Web constructor.
* @param array $options
*/
public function __construct(array $options)
{
parent::__construct($options);
$this->options->set('method', 'alipay.trade.page.pay');
$this->params->set('product_code', 'FAST_INSTANT_TRADE_PAY');
}
/**
* 创建数据操作
* @param array $options
* @return string
*/
public function apply($options)
{
parent::applyData($options);
return $this->buildPayHtml();
}
}

174
README.md
View File

@ -1,174 +0,0 @@
[![Latest Stable Version](https://poser.pugx.org/zoujingli/wechat-developer/v/stable)](https://packagist.org/packages/zoujingli/wechat-developer)
[![Latest Unstable Version](https://poser.pugx.org/zoujingli/wechat-developer/v/unstable)](https://packagist.org/packages/zoujingli/wechat-developer)
[![Total Downloads](https://poser.pugx.org/zoujingli/wechat-developer/downloads)](https://packagist.org/packages/zoujingli/wechat-developer)
[![License](https://poser.pugx.org/zoujingli/wechat-developer/license)](https://packagist.org/packages/zoujingli/wechat-developer)
WeChatDeveloper for PHP
--
* WeChatDeveloper 是基于 [wechat-php-sdk](https://github.com/zoujingli/wechat-php-sdk) 重构,优化并完善;
* 运行最底要求 PHP 版本 5.4 , 建议在 PHP7 上运行以获取最佳性能;
* WeChatDeveloper 针对 access_token 失效增加了自动刷新机制;
* 微信的部分接口需要缓存数据在本地,因此对目录需要有写权限;
* 我们鼓励大家使用 composer 来管理您的第三方库,方便后期更新操作;
* WeChatDeveloper 已历经数个线上项目考验,欢迎 fork 或 star 此项目。
Documentation
--
PHP开发技术交流QQ群 513350915
[![PHP微信开发群 (SDK)](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=ae25cf789dafbef62e50a980ffc31242f150bc61a61164458216dd98c411832a)
WeChatDeveloper 是基于官方接口封装,在做微信开发前,必需先阅读微信官方文档。
* 微信官方文档https://mp.weixin.qq.com/wiki
* 商户支付文档https://pay.weixin.qq.com/wiki/doc/api/index.html
针对 WeChatDeveloper 也有一准备了帮助资料可供参考。
* ThinkAdminhttps://github.com/zoujingli/Think.Admin
* 开发文档地址https://www.kancloud.cn/zoujingli/wechat-developer
Repositorie
--
WeChatDeveloper 为开源项目,允许把它用于任何地方,不受任何约束,欢迎 fork 项目。
* Gitee 托管地址https://gitee.com/zoujingli/WeChatDeveloper
* GitHub 托管地址https://github.com/zoujingli/WeChatDeveloper
ClassMap
--
|文件名|类名|描述|类型|加载 ①|
|---|---|---|---|---|
| Card.php | WeChat\Card | 微信卡券接口支持 | 认证服务号 | \We::WeChatCard() |
| Custom.php | WeChat\Custom | 微信客服消息接口支持 | 认证服务号 | \We::WeChatCustom() |
| Media.php | WeChat\Media | 微信媒体素材接口支持 | 认证服务号 | \We::WeChatMedia() |
| Oauth.php | WeChat\Oauth | 微信网页授权消息类接口 | 认证服务号 | \We::WeChatOauth() |
| Pay.php | WeChat\Pay | 微信支付类接口 | 认证服务号 | \We::WeChatPay() |
| Product.php | WeChat\Product | 微信商店类接口 | 认证服务号 | \We::WeChatProduct() |
| Qrcode.php | WeChat\Qrcode | 微信二维码接口支持 | 认证服务号 | \We::WeChatQrcode() |
| Receive.php | WeChat\Receive | 微信推送事件消息处理支持 | 认证服务号 | \We::WeChatReceive() |
| Scan.php | WeChat\Scan | 微信扫一扫接口支持 | 认证服务号 | \We::WeChatScan() |
| Script.php | WeChat\Script | 微信前端JSSDK支持 | 认证服务号 | \We::WeChatScript() |
| Shake.php | WeChat\Shake | 微信蓝牙设备揺一揺接口 | 认证服务号 | \We::WeChatShake() |
| Tags.php | WeChat\Tags | 微信粉丝标签接口支持 | 认证服务号 | \We::WeChatTags() |
| Template.php | WeChat\Template | 微信模板消息接口支持 | 认证服务号 | \We::WeChatTemplate() |
| User.php | WeChat\User | 微信粉丝管理接口支持 | 认证服务号 | \We::WeChatCard() |
| Wifi.php | WeChat\Wifi | 微信门店WIFI管理支持 | 认证服务号 | \We::WeChatWifi() |
| Bill.php | WePay\Bill | 微信商户账单及评论 | 微信支付 | \We::WePayBill() |
| Coupon.php | WePay\Coupon | 微信商户代金券 | 微信支付 | \We::WePayCoupon() |
| Order.php | WePay\Order | 微信商户订单 | 微信支付 | \We::WePayOrder() |
| Redpack.php | WePay\Redpack | 微信红包支持 | 微信支付 | \We::WePayRedpack() |
| Refund.php | WePay\Refund | 微信商户退款 | 微信支付 | \We::WePayRefund() |
| Transfers.php | WePay\Transfers | 微信商户打款到零钱 | 微信支付 | \We::WePayTransfers() |
| TransfersBank.php | WePay\TransfersBank | 微信商户打款到银行卡 | 微信支付 | \We::WePayTransfersBank() |
| Crypt.php | WeMini\Crypt | 微信小程序数据加密处理 | 微信小程序 | \We::WeMiniCrypt() |
| Plugs.php | WeMini\Plugs | 微信小程序插件管理 | 微信小程序 | \We::WeMiniPlugs() |
| Poi.php | WeMini\Poi | 微信小程序地址管理 | 微信小程序 | \We::WeMiniPoi() |
| Qrcode.php | WeMini\Qrcode | 微信小程序二维码管理 | 微信小程序 | \We::WeMiniCrypt() |
| Template.php | WeMini\Template | 微信小程序模板消息支持 | 微信小程序 | \We::WeMiniTemplate() |
| Total.php | WeMini\Total | 微信小程序数据接口 | 微信小程序 | \We::WeMiniTotal() |
Install
--
1.1 通过 Composer 来管理安装
```shell
# 首次安装 线上版本(稳定)
composer require zoujingli/wechat-developer
# 首次安装 开发版本(开发)
composer require zoujingli/wechat-developer dev-master
# 更新 WeChatDeveloper
composer update zoujingli/wechat-developer
```
1.2 如果不使用 Composer 可以下载 WeChatDeveloper 并解压到项目中
```php
# 在项目中加载初始化文件
include "您的目录/WeChatDeveloper/include.php";
```
2.1 接口实例所需参数
```php
$config = [
'token' => 'test',
'appid' => 'wx60a43dd8161666d4',
'appsecret' => '71308e96a204296c57d7cd4b21b883e8',
'encodingaeskey' => 'BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5',
// 配置商户支付参数(可选,在使用支付功能时需要)
'mch_id' => "1235704602",
'mch_key' => 'IKI4kpHjU94ji3oqre5zYaQMwLHuZPmj',
// 配置商户支付双向证书目录(可选,在使用退款|打款|红包时需要)
'ssl_key' => '',
'ssl_cer' => '',
// 缓存目录配置(可选,需拥有读写权限)
'cache_path' => '',
];
```
3.1 实例指定接口
```php
try {
// 实例对应的接口对象
$user = new \WeChat\User($config);
// 调用接口对象方法
$list = $user->getUserList();
// 处理返回的结果
echo '<pre>';
var_export($list);
} catch (Exception $e) {
// 出错啦,处理下吧
echo $e->getMessage() . PHP_EOL;
}
```
Encapsulation
--
* 接入验证 (初级权限)
* 自动回复(文本、图片、语音、视频、音乐、图文) (初级权限)
* 菜单操作(查询、创建、删除) (菜单权限)
* 客服消息(文本、图片、语音、视频、音乐、图文) (认证权限)
* 二维码创建临时、永久二维码获取二维码URL (服务号、认证权限)
* 长链接转短链接接口 (服务号、认证权限)
* 标签操作(查询、创建、修改、移动用户到标签) (认证权限)
* 网页授权(基本授权,用户信息授权) (服务号、认证权限)
* 用户信息(查询用户基本信息、获取关注者列表) (认证权限)
* 多客服功能(客服管理、获取客服记录、客服会话管理) (认证权限)
* 媒体文件(上传、获取) (认证权限)
* 高级群发 (认证权限)
* 模板消息(设置所属行业、添加模板、发送模板消息) (服务号、认证权限)
* 卡券管理(创建、修改、删除、发放、门店管理等) (认证权限)
* 语义理解 (服务号、认证权限)
* 获取微信服务器IP列表 (初级权限)
* 微信JSAPI授权(获取ticket、获取签名) (初级权限)
* 数据统计(用户、图文、消息、接口分析数据) (认证权限)
* 微信支付(网页支付、扫码支付、交易退款、给粉丝打款)(认证服务号并开通支付功能)
Permission
--
* 初级权限:基本权限,任何正常的公众号都有此权限
* 菜单权限:正常的服务号、认证后的订阅号拥有此权限
* 认证权限:分为订阅号、服务号认证,如前缀服务号则仅认证的服务号有此权限
* 支付权限:仅认证后的服务号可以申请此权限
Copyright
--
* WeChatDeveloper 基于`MIT`协议发布,任何人可以用在任何地方,不受约束
* WeChatDeveloper 部分代码来自互联网,若有异议,可以联系作者进行删除
Sponsor
--
![赞助](http://zoujingli.oschina.io/static/pay.png)

View File

@ -1,29 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
return [
'token' => 'test',
'appid' => 'wx60a43dd8161666d4',
'appsecret' => '71308e96a204296c57d7cd4b21b883e8',
'encodingaeskey' => 'BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5',
// 配置商户支付参数
'mch_id' => "1332187001",
'mch_key' => 'A82DC5BD1F3359081049C568D8502BC5',
// 配置商户支付双向证书目录 p12 | key,cert 二选一两者都配置时p12优先
// 'ssl_p12' => __DIR__ . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'apiclient_cert.p12',
'ssl_key' => __DIR__ . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'apiclient_key.pem',
'ssl_cer' => __DIR__ . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'apiclient_cert.pem',
// 配置缓存目录,需要拥有写权限
'cache_path' => '',
];

View File

@ -1,20 +0,0 @@
<?php
include '../include.php';
// 小程序配置
$config = [
'appid' => 'wx6bb7b70258da09c6',
'appsecret' => '78b7b8d65bd67b078babf951d4342b42',
];
// 解码数据
$iv = 'ltM/wT7hsAl0TijEBI4v/g==';
$code = '013LyiTR0TwjC92QjJRR0mEsTR0LyiT3';
$decode = 'eIoVtIC2YzLCnrwiIs1IBbXMvC0vyL8bo1IhD38fUQIRbk3lgTWa0Hdw/Ty7NTs3iu7YlqqZBti+cxd6dCfeXBUQwTO2QpbHg0WTeDAdrihsHRHm4dCWdfTx8rzDloGbNOIsKdRElIhUH5YFdiTr5AYiufUDb34cwJ4GNWLAUq4bR0dmFeVEi+3nfwe2MAjGYDl4aq719VLsHodOggK6lXZvM5wjoDyuZsK2dPqJr3/Ji30Z0mdyFq32R4uR3rtJH/h+Rj0+/QmE9QYG7Y6Z48hgPE8cpnhRQNwH49jnC/zKZ9wtDkQ/J8J3Ed2i58zcuY01v8IV+pZ8oBUKXfO5ha+APOxtBSTzyHraU/2RGo8UWtOF6h64OQZhd/UQQy362eyc/qoq8sF9JnEFRP0mRmTDJ+u9oyDhxswCu6x8V73ERWaJeEGSCyjiGpep7/DxZ6eSSBq36OB0BWBkJqsq9Q==';
$sessionKey = 'OetNxl86B/yMpbwG6wtMEw==';
$mini = new WeMini\Crypt($config);
echo '<pre>';
//print_r($mini->session($code));
print_r($mini->decode($iv, $sessionKey, $decode));
//print_r($mini->userInfo($code, $iv, $decode));

View File

@ -1,25 +0,0 @@
<?php
include '../include.php';
// 小程序配置
$config = [
'appid' => 'wx6bb7b70258da09c6',
'appsecret' => '78b7b8d65bd67b078babf951d4342b42',
];
//We::config($config);
$mini = We::WeMiniQrcode($config);
//$mini = new WeMini\Qrcode($config);
//echo '<pre>';
try {
header('Content-type:image/jpeg');//输出的类型
// echo $mini->createDefault('pages/index?query=1');
// echo $mini->createMiniScene('432432', 'pages/index/index');
echo $mini->createMiniPath('pages/index?query=1');
} catch (Exception $e) {
var_dump($e->getMessage());
}

View File

@ -1,53 +0,0 @@
<?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);
// 创建JSAPI参数签名
$options = $wechat->createParamsForJsApi($result['prepay_id']);
echo '<pre>';
echo "\n--- 创建预支付码 ---\n";
var_export($result);
echo "\n\n--- JSAPI 及 H5 参数 ---\n";
var_export($options);
} catch (Exception $e) {
// 出错啦,处理下吧
echo $e->getMessage() . PHP_EOL;
}

46
We.php
View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
use WeChat\Contracts\DataArray;
@ -23,6 +25,16 @@ use WeChat\Exceptions\InvalidInstanceException;
* @author Anyon<zoujingli@qq.com>
* @date 2018/05/24 13:23
*
* ----- AliPay ----
* @method \AliPay\App AliPayApp($options) static 支付宝App支付网关
* @method \AliPay\Bill AliPayBill($options) static 支付宝电子面单下载
* @method \AliPay\Pos AliPayPos($options) static 支付宝刷卡支付
* @method \AliPay\Scan AliPayScan($options) static 支付宝扫码支付
* @method \AliPay\Trade AliPayTrade($options) static 支付宝标准接口
* @method \AliPay\Transfer AliPayTransfer($options) static 支付宝转账到账户
* @method \AliPay\Wap AliPayWap($options) static 支付宝手机网站支付
* @method \AliPay\Web AliPayWeb($options) static 支付宝网站支付
*
* ----- WeChat -----
* @method \WeChat\Card WeChatCard($options = []) static 微信卡券管理
* @method \WeChat\Custom WeChatCustom($options = []) static 微信客服消息
@ -33,7 +45,7 @@ use WeChat\Exceptions\InvalidInstanceException;
* @method \WeChat\Pay WeChatPay($options = []) static 微信支付商户
* @method \WeChat\Product WeChatProduct($options = []) static 微信商店管理
* @method \WeChat\Qrcode WeChatQrcode($options = []) static 微信二维码管理
* @method \WeChat\Receive WeChatReceive($options = []) static 微信推送管理
* @method \WeChat\Receive WeChatReceive($options = [], $showEchoStr = true) static 微信推送管理
* @method \WeChat\Scan WeChatScan($options = []) static 微信扫一扫接入管理
* @method \WeChat\Script WeChatScript($options = []) static 微信前端支持
* @method \WeChat\Shake WeChatShake($options = []) static 微信揺一揺周边
@ -41,23 +53,41 @@ use WeChat\Exceptions\InvalidInstanceException;
* @method \WeChat\Template WeChatTemplate($options = []) static 微信模板消息
* @method \WeChat\User WeChatUser($options = []) static 微信粉丝管理
* @method \WeChat\Wifi WeChatWifi($options = []) static 微信门店WIFI管理
* @method \WeChat\Draft WeChatDraft($options = []) static 微信草稿箱
* @method \WeChat\Freepublish WeChatFreepublish($options = []) static 微信发布能力
*
* ----- WeMini -----
* @method \WeMini\Crypt WeMiniCrypt($options = []) static 小程序数据加密处理
* @method \WeMini\Delivery WeMiniDelivery($options = []) static 小程序即时配送
* @method \WeMini\Shipping WeMiniShipping($options = []) satic 小程序发货信息
* @method \WeMini\Guide WeMiniGuide($options = []) static 小程序导购助手
* @method \WeMini\Image WeMiniImage($options = []) static 小程序图像处理
* @method \WeMini\Live WeMiniLive($options = []) static 小程序直播接口
* @method \WeMini\Logistics WeMiniLogistics($options = []) static 小程序物流助手
* @method \WeMini\Message WeMiniMessage($options = []) static 小程序动态消息
* @method \WeMini\Newtmpl WeMiniNewtmpl($options = []) static 小程序订阅消息
* @method \WeMini\Ocr WeMiniOcr($options = []) static 小程序ORC服务
* @method \WeMini\Operation WeMiniOperation($options = []) static 小程序运维中心
* @method \WeMini\Plugs WeMiniPlugs($options = []) static 小程序插件管理
* @method \WeMini\Poi WeMiniPoi($options = []) static 小程序地址管理
* @method \WeMini\Qrcode WeMiniQrcode($options = []) static 小程序二维码管理
* @method \WeMini\Scheme WeMiniScheme($options = []) static 小程序 URL-Scheme
* @method \WeMini\Search WeMiniSearch($options = []) static 小程序搜索
* @method \WeMini\Security WeMiniSecurity($options = []) static 小程序内容安全
* @method \WeMini\Soter WeMiniSoter($options = []) static 小程序生物认证
* @method \WeMini\Template WeMiniTemplate($options = []) static 小程序模板消息支持
* @method \WeMini\Total WeMiniTotal($options = []) static 小程序数据接口
*
* ----- WePay -----
* @method \WePay\Bill WePayBill($options = []) static 微信商户账单及评论
* @method \WePay\Order WePayOrder($options = []) static 微信商户订单
* @method \WePay\Refund WePayRefund($options = []) static 微信商户退款
* @method \WePay\Coupon WePayCoupon($options = []) static 微信商户代金券
* @method \WePay\Custom WePayCustom($options = []) static 微信商户海关
* @method \WePay\Refund WePayRefund($options = []) static 微信商户退款
* @method \WePay\Redpack WePayRedpack($options = []) static 微信红包支持
* @method \WePay\Transfers WePayTransfers($options = []) static 微信商户打款到零钱
* @method \WePay\TransfersBank WePayTransfersBank($options = []) static 微信商户打款到银行卡
* @method \WePay\ProfitSharing WePayProfitSharing($options = []) static 微信分账
*/
class We
{
@ -65,7 +95,7 @@ class We
* 定义当前版本
* @var string
*/
const VERSION = '1.1.12';
const VERSION = '1.2.54';
/**
* 静态配置
@ -102,6 +132,10 @@ class We
$class = 'WeChat\\' . substr($name, 6);
} elseif (substr($name, 0, 6) === 'WeMini') {
$class = 'WeMini\\' . substr($name, 6);
} elseif (substr($name, 0, 6) === 'AliPay') {
$class = 'AliPay\\' . substr($name, 6);
} elseif (substr($name, 0, 7) === 'WePayV3') {
$class = 'WePayV3\\' . substr($name, 7);
} elseif (substr($name, 0, 5) === 'WePay') {
$class = 'WePay\\' . substr($name, 5);
}

View File

@ -3,18 +3,19 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\BasicWeChat;
/**
@ -34,38 +35,35 @@ class Card extends BasicWeChat
public function create(array $data)
{
$url = "https://api.weixin.qq.com/card/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 设置买单接口
* @param string $card_id
* @param bool $is_open
* @param string $cardId
* @param bool $isOpen
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function setPaycell($card_id, $is_open = true)
public function setPaycell($cardId, $isOpen = true)
{
$url = "https://api.weixin.qq.com/card/paycell/set?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id, 'is_open' => $is_open]);
return $this->callPostApi($url, ['card_id' => $cardId, 'is_open' => $isOpen]);
}
/**
* 设置自助核销接口
* @param string $card_id
* @param bool $is_open
* @param string $cardId
* @param bool $isOpen
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function setConsumeCell($card_id, $is_open = true)
public function setConsumeCell($cardId, $isOpen = true)
{
$url = "https://api.weixin.qq.com/card/selfconsumecell/set?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id, 'is_open' => $is_open]);
return $this->callPostApi($url, ['card_id' => $cardId, 'is_open' => $isOpen]);
}
/**
@ -78,8 +76,7 @@ class Card extends BasicWeChat
public function createQrc(array $data)
{
$url = "https://api.weixin.qq.com/card/qrcode/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -92,66 +89,61 @@ class Card extends BasicWeChat
public function createLandingPage(array $data)
{
$url = "https://api.weixin.qq.com/card/landingpage/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 导入自定义code
* @param string $card_id
* @param string $cardId
* @param array $code
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function deposit($card_id, array $code)
public function deposit($cardId, array $code)
{
$url = "https://api.weixin.qq.com/card/code/deposit?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id, 'code' => $code]);
return $this->callPostApi($url, ['card_id' => $cardId, 'code' => $code]);
}
/**
* 查询导入code数目
* @param string $card_id
* @param string $cardId
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getDepositCount($card_id)
public function getDepositCount($cardId)
{
$url = "https://api.weixin.qq.com/card/code/getdepositcount?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id]);
return $this->callPostApi($url, ['card_id' => $cardId]);
}
/**
* 核查code接口
* @param string $card_id 进行导入code的卡券ID
* @param string $cardId 进行导入code的卡券ID
* @param array $code 已经微信卡券后台的自定义code上限为100个
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function checkCode($card_id, array $code)
public function checkCode($cardId, array $code)
{
$url = "https://api.weixin.qq.com/card/code/checkcode?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id, 'code' => $code]);
return $this->callPostApi($url, ['card_id' => $cardId, 'code' => $code]);
}
/**
* 图文消息群发卡券
* @param string $card_id
* @param string $cardId
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getNewsHtml($card_id)
public function getNewsHtml($cardId)
{
$url = "https://api.weixin.qq.com/card/mpnews/gethtml?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id]);
return $this->callPostApi($url, ['card_id' => $cardId]);
}
/**
@ -165,27 +157,25 @@ class Card extends BasicWeChat
public function setTestWhiteList($openids = [], $usernames = [])
{
$url = "https://api.weixin.qq.com/card/testwhitelist/set?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['openid' => $openids, 'username' => $usernames]);
return $this->callPostApi($url, ['openid' => $openids, 'username' => $usernames]);
}
/**
* 线下核销查询Code
* @param string $code 单张卡券的唯一标准
* @param string $card_id 卡券ID代表一类卡券。自定义code卡券必填
* @param bool $check_consume 是否校验code核销状态填入true和false时的code异常状态返回数据不同
* @param string $cardId 卡券ID代表一类卡券。自定义code卡券必填
* @param bool $checkConsume 是否校验code核销状态填入true和false时的code异常状态返回数据不同
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCode($code, $card_id = null, $check_consume = null)
public function getCode($code, $cardId = null, $checkConsume = null)
{
$data = ['code' => $code];
is_null($card_id) || $data['card_id'] = $card_id;
is_null($check_consume) || $data['check_consume'] = $check_consume;
is_null($cardId) || $data['card_id'] = $cardId;
is_null($checkConsume) || $data['check_consume'] = $checkConsume;
$url = "https://api.weixin.qq.com/card/code/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -201,86 +191,80 @@ class Card extends BasicWeChat
$data = ['code' => $code];
is_null($card_id) || $data['card_id'] = $card_id;
$url = "https://api.weixin.qq.com/card/code/consume?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* Code解码接口
* @param string $encrypt_code
* @param string $encryptCode
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function decrypt($encrypt_code)
public function decrypt($encryptCode)
{
$url = "https://api.weixin.qq.com/card/code/decrypt?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['encrypt_code' => $encrypt_code]);
return $this->callPostApi($url, ['encrypt_code' => $encryptCode]);
}
/**
* 获取用户已领取卡券接口
* @param string $openid
* @param null|string $card_id
* @param null|string $cardId
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCardList($openid, $card_id = null)
public function getCardList($openid, $cardId = null)
{
$data = ['openid' => $openid];
is_null($card_id) || $data['card_id'] = $card_id;
is_null($cardId) || $data['card_id'] = $cardId;
$url = "https://api.weixin.qq.com/card/user/getcardlist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 查看卡券详情
* @param string $card_id
* @param string $cardId
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCard($card_id)
public function getCard($cardId)
{
$url = "https://api.weixin.qq.com/card/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id]);
return $this->callPostApi($url, ['card_id' => $cardId]);
}
/**
* 批量查询卡券列表
* @param int $offset 查询卡列表的起始偏移量从0开始即offset: 5是指从从列表里的第六个开始读取
* @param int $count 需要查询的卡片的数量数量最大50
* @param array $status_list 支持开发者拉出指定状态的卡券列表
* @param array $statusList 支持开发者拉出指定状态的卡券列表
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function batchGet($offset, $count = 50, array $status_list = [])
public function batchGet($offset, $count = 50, array $statusList = [])
{
$data = ['offset' => $offset, 'count' => $count];
empty($status_list) || $data['status_list'] = $status_list;
empty($statusList) || $data['status_list'] = $statusList;
$url = "https://api.weixin.qq.com/card/batchget?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 更改卡券信息接口
* @param string $card_id
* @param array $member_card
* @param string $cardId
* @param array $memberCard
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function updateCard($card_id, array $member_card)
public function updateCard($cardId, array $memberCard)
{
$url = "https://api.weixin.qq.com/card/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id, 'member_card' => $member_card]);
return $this->callPostApi($url, ['card_id' => $cardId, 'member_card' => $memberCard]);
}
/**
@ -295,11 +279,10 @@ class Card extends BasicWeChat
public function modifyStock($card_id, $increase_stock_value = null, $reduce_stock_value = null)
{
$data = ['card_id' => $card_id];
is_null($increase_stock_value) || $data['increase_stock_value'] = $increase_stock_value;
is_null($reduce_stock_value) || $data['reduce_stock_value'] = $reduce_stock_value;
is_null($increase_stock_value) || $data['increase_stock_value'] = $increase_stock_value;
$url = "https://api.weixin.qq.com/card/modifystock?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -316,76 +299,71 @@ class Card extends BasicWeChat
$data = ['code' => $code, 'new_code' => $new_code];
is_null($card_id) || $data['card_id'] = $card_id;
$url = "https://api.weixin.qq.com/card/code/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 删除卡券接口
* @param string $card_id
* @param string $cardId
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function deleteCard($card_id)
public function deleteCard($cardId)
{
$url = "https://api.weixin.qq.com/card/delete?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id]);
return $this->callPostApi($url, ['card_id' => $cardId]);
}
/**
* 设置卡券失效接口
* @param string $code
* @param string $card_id
* @param string $cardId
* @param null|string $reason
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function unAvailable($code, $card_id, $reason = null)
public function unAvailable($code, $cardId, $reason = null)
{
$data = ['code' => $code, 'card_id' => $card_id];
$data = ['code' => $code, 'card_id' => $cardId];
is_null($reason) || $data['reason'] = $reason;
$url = "https://api.weixin.qq.com/card/code/unavailable?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 拉取卡券概况数据接口
* @param string $begin_date 查询数据的起始时间
* @param string $end_date 查询数据的截至时间
* @param string $cond_source 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据)
* @param string $beginDate 查询数据的起始时间
* @param string $endDate 查询数据的截至时间
* @param string $condSource 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据)
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCardBizuininfo($begin_date, $end_date, $cond_source)
public function getCardBizuininfo($beginDate, $endDate, $condSource)
{
$data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'cond_source' => $cond_source];
$url = "https://api.weixin.qq.com/datacube/getcardbizuininfo?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['begin_date' => $beginDate, 'end_date' => $endDate, 'cond_source' => $condSource];
return $this->callPostApi($url, $data);
}
/**
* 获取免费券数据接口
* @param string $begin_date 查询数据的起始时间
* @param string $end_date 查询数据的截至时间
* @param integer $cond_source 卡券来源0为公众平台创建的卡券数据、1是API创建的卡券数据
* @param null $card_id 卡券ID
* @param string $beginDate 查询数据的起始时间
* @param string $endDate 查询数据的截至时间
* @param integer $condSource 卡券来源0为公众平台创建的卡券数据、1是API创建的卡券数据
* @param null $cardId 卡券ID
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCardCardinfo($begin_date, $end_date, $cond_source, $card_id = null)
public function getCardCardinfo($beginDate, $endDate, $condSource, $cardId = null)
{
$data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'cond_source' => $cond_source];
is_null($card_id) || $data['card_id'] = $card_id;
$url = "https://api.weixin.qq.com/datacube/getcardcardinfo?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['begin_date' => $beginDate, 'end_date' => $endDate, 'cond_source' => $condSource];
is_null($cardId) || $data['card_id'] = $cardId;
return $this->callPostApi($url, $data);
}
@ -399,8 +377,7 @@ class Card extends BasicWeChat
public function activateMemberCard(array $data)
{
$url = 'https://api.weixin.qq.com/card/membercard/activate?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -414,23 +391,21 @@ class Card extends BasicWeChat
public function setActivateMemberCardUser(array $data)
{
$url = 'https://api.weixin.qq.com/card/membercard/activateuserform/set?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 获取用户提交资料
* 根据activate_ticket获取到用户填写的信息
* @param string $activate_ticket
* @param string $activateTicket
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getActivateMemberCardTempinfo($activate_ticket)
public function getActivateMemberCardTempinfo($activateTicket)
{
$url = 'https://api.weixin.qq.com/card/membercard/activatetempinfo/get?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['activate_ticket' => $activate_ticket]);
return $this->callPostApi($url, ['activate_ticket' => $activateTicket]);
}
/**
@ -443,58 +418,54 @@ class Card extends BasicWeChat
public function updateMemberCardUser(array $data)
{
$url = 'https://api.weixin.qq.com/card/membercard/updateuser?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 拉取会员卡概况数据接口
* @param string $begin_date 查询数据的起始时间
* @param string $end_date 查询数据的截至时间
* @param string $cond_source 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据)
* @param string $beginDate 查询数据的起始时间
* @param string $endDate 查询数据的截至时间
* @param string $condSource 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据)
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCardMemberCardinfo($begin_date, $end_date, $cond_source)
public function getCardMemberCardinfo($beginDate, $endDate, $condSource)
{
$data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'cond_source' => $cond_source];
$url = "https://api.weixin.qq.com/datacube/getcardmembercardinfo?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['begin_date' => $beginDate, 'end_date' => $endDate, 'cond_source' => $condSource];
return $this->callPostApi($url, $data);
}
/**
* 拉取单张会员卡数据接口
* @param string $begin_date 查询数据的起始时间
* @param string $end_date 查询数据的截至时间
* @param string $card_id 卡券id
* @param string $beginDate 查询数据的起始时间
* @param string $endDate 查询数据的截至时间
* @param string $cardId 卡券id
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCardMemberCardDetail($begin_date, $end_date, $card_id)
public function getCardMemberCardDetail($beginDate, $endDate, $cardId)
{
$data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'card_id' => $card_id];
$url = "https://api.weixin.qq.com/datacube/getcardmembercarddetail?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['begin_date' => $beginDate, 'end_date' => $endDate, 'card_id' => $cardId];
return $this->callPostApi($url, $data);
}
/**
* 拉取会员信息(积分查询)接口
* @param string $card_id 查询会员卡的cardid
* @param string $cardId 查询会员卡的cardid
* @param string $code 所查询用户领取到的code值
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getCardMemberCard($card_id, $code)
public function getCardMemberCard($cardId, $code)
{
$data = ['card_id' => $card_id, 'code' => $code];
$data = ['card_id' => $cardId, 'code' => $code];
$url = "https://api.weixin.qq.com/card/membercard/userinfo/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -507,36 +478,33 @@ class Card extends BasicWeChat
public function payGiftCard(array $data)
{
$url = "https://api.weixin.qq.com/card/paygiftcard/add?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 删除支付后投放卡券规则
* @param integer $rule_id 支付即会员的规则名称
* @param integer $ruleId 支付即会员的规则名称
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function delPayGiftCard($rule_id)
public function delPayGiftCard($ruleId)
{
$url = "https://api.weixin.qq.com/card/paygiftcard/add?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['rule_id' => $rule_id]);
return $this->callPostApi($url, ['rule_id' => $ruleId]);
}
/**
* 查询支付后投放卡券规则详情
* @param integer $rule_id 要查询规则id
* @param integer $ruleId 要查询规则id
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getPayGiftCard($rule_id)
public function getPayGiftCard($ruleId)
{
$url = "https://api.weixin.qq.com/card/paygiftcard/getbyid?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['rule_id' => $rule_id]);
return $this->callPostApi($url, ['rule_id' => $ruleId]);
}
/**
@ -550,10 +518,9 @@ class Card extends BasicWeChat
*/
public function batchGetPayGiftCard($offset = 0, $count = 10, $effective = true)
{
$data = ['type' => 'RULE_TYPE_PAY_MEMBER_CARD', 'offset' => $offset, 'count' => $count, 'effective' => $effective];
$url = "https://api.weixin.qq.com/card/paygiftcard/batchget?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['type' => 'RULE_TYPE_PAY_MEMBER_CARD', 'offset' => $offset, 'count' => $count, 'effective' => $effective];
return $this->callPostApi($url, $data);
}
/**
@ -566,8 +533,7 @@ class Card extends BasicWeChat
public function addActivity(array $data)
{
$url = "https://api.weixin.qq.com/card/mkt/activity/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -579,23 +545,21 @@ class Card extends BasicWeChat
public function payActivate()
{
$url = "https://api.weixin.qq.com/card/pay/activate?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 对优惠券批价
* @param string $card_id 需要来配置库存的card_id
* @param string $cardId 需要来配置库存的card_id
* @param integer $quantity 本次需要兑换的库存数目
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getPayprice($card_id, $quantity)
public function getPayprice($cardId, $quantity)
{
$url = "POST https://api.weixin.qq.com/card/pay/getpayprice?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['card_id' => $card_id, 'quantity' => $quantity]);
return $this->callPostApi($url, ['card_id' => $cardId, 'quantity' => $quantity]);
}
/**
@ -607,53 +571,49 @@ class Card extends BasicWeChat
public function getCoinsInfo()
{
$url = "https://api.weixin.qq.com/card/pay/getcoinsinfo?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 确认兑换库存接口
* @param string $card_id 需要来兑换库存的card_id
* @param string $cardId 需要来兑换库存的card_id
* @param integer $quantity 本次需要兑换的库存数目
* @param string $order_id 仅可以使用上面得到的订单号,保证批价有效性
* @param string $orderId 仅可以使用上面得到的订单号,保证批价有效性
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function payConfirm($card_id, $quantity, $order_id)
public function payConfirm($cardId, $quantity, $orderId)
{
$data = ['card_id' => $card_id, 'quantity' => $quantity, 'order_id' => $order_id];
$url = "https://api.weixin.qq.com/card/pay/confirm?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['card_id' => $cardId, 'quantity' => $quantity, 'order_id' => $orderId];
return $this->callPostApi($url, $data);
}
/**
* 充值券点接口
* @param integer $coin_count
* @param integer $coinCount
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function payRecharge($coin_count)
public function payRecharge($coinCount)
{
$url = "https://api.weixin.qq.com/card/pay/recharge?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['coin_count' => $coin_count]);
return $this->callPostApi($url, ['coin_count' => $coinCount]);
}
/**
* 查询订单详情接口
* @param string $order_id
* @param string $orderId
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function payGetOrder($order_id)
public function payGetOrder($orderId)
{
$url = "https://api.weixin.qq.com/card/pay/getorder?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['order_id' => $order_id]);
return $this->callPostApi($url, ['order_id' => $orderId]);
}
/**
@ -666,9 +626,19 @@ class Card extends BasicWeChat
public function payGetList(array $data)
{
$url = "https://api.weixin.qq.com/card/pay/getorderlist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
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

@ -0,0 +1,428 @@
<?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 WeChat\Contracts;
use WeChat\Exceptions\InvalidArgumentException;
use WeChat\Exceptions\InvalidResponseException;
/**
* 支付宝支付基类
* Class AliPay
* @package AliPay\Contracts
*/
abstract class BasicAliPay
{
/**
* 支持配置
* @var DataArray
*/
protected $config;
/**
* 当前请求数据
* @var DataArray
*/
protected $options;
/**
* DzContent数据
* @var DataArray
*/
protected $params;
/**
* 静态缓存
* @var static
*/
protected static $cache;
/**
* 正常请求网关
* @var string
*/
protected $gateway = 'https://openapi.alipay.com/gateway.do?charset=utf-8';
/**
* AliPay constructor.
* @param array $options
*/
public function __construct($options)
{
if (empty($options['appid'])) {
throw new InvalidArgumentException('Missing Config -- [appid]');
}
if (empty($options['public_key']) && !empty($options['alipay_cert_path']) && is_file($options['alipay_cert_path'])) {
$options['public_key'] = file_get_contents($options['alipay_cert_path']);
}
if (empty($options['private_key']) && !empty($options['private_key_path']) && is_file($options['private_key_path'])) {
$options['private_key'] = file_get_contents($options['private_key_path']);
}
if (empty($options['public_key'])) {
throw new InvalidArgumentException('Missing Config -- [public_key]');
}
if (empty($options['private_key'])) {
throw new InvalidArgumentException('Missing Config -- [private_key]');
}
if (!empty($options['debug'])) {
$this->gateway = 'https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8';
}
$this->params = new DataArray([]);
$this->config = new DataArray($options);
$this->options = new DataArray([
'app_id' => $this->config->get('appid'),
'charset' => empty($options['charset']) ? 'utf-8' : $options['charset'],
'format' => 'JSON',
'version' => '1.0',
'sign_type' => empty($options['sign_type']) ? 'RSA2' : $options['sign_type'],
'timestamp' => date('Y-m-d H:i:s'),
]);
if (isset($options['notify_url']) && $options['notify_url'] !== '') {
$this->options->set('notify_url', $options['notify_url']);
}
if (isset($options['return_url']) && $options['return_url'] !== '') {
$this->options->set('return_url', $options['return_url']);
}
if (isset($options['app_auth_token']) && $options['app_auth_token'] !== '') {
$this->options->set('app_auth_token', $options['app_auth_token']);
}
// 证书模式读取证书
$appCertPath = $this->config->get('app_cert_path');
$aliRootPath = $this->config->get('alipay_root_path');
if (!$this->config->get('app_cert') && !empty($appCertPath) && is_file($appCertPath)) {
$this->config->set('app_cert', file_get_contents($appCertPath));
}
if (!$this->config->get('root_cert') && !empty($aliRootPath) && is_file($aliRootPath)) {
$this->config->set('root_cert', file_get_contents($aliRootPath));
}
}
/**
* 静态创建对象
* @param array $config
* @return static
*/
public static function instance(array $config)
{
$key = md5(get_called_class() . serialize($config));
if (isset(self::$cache[$key])) return self::$cache[$key];
return self::$cache[$key] = new static($config);
}
/**
* 查询支付宝订单状态
* @param string $outTradeNo
* @return array|boolean
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query($outTradeNo = '')
{
$this->options->set('method', 'alipay.trade.query');
return $this->getResult(['out_trade_no' => $outTradeNo]);
}
/**
* 支付宝订单退款操作
* @param array|string $options 退款参数或退款商户订单号
* @param null $refundAmount 退款金额
* @return array|boolean
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function refund($options, $refundAmount = null)
{
if (!is_array($options)) $options = ['out_trade_no' => $options, 'refund_amount' => $refundAmount];
$this->options->set('method', 'alipay.trade.refund');
return $this->getResult($options);
}
/**
* 关闭支付宝进行中的订单
* @param array|string $options
* @return array|boolean
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function close($options)
{
if (!is_array($options)) $options = ['out_trade_no' => $options];
$this->options->set('method', 'alipay.trade.close');
return $this->getResult($options);
}
/**
* 获取通知数据
*
* @param boolean $needSignType 是否需要sign_type字段
* @param array $parameters
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function notify($needSignType = false, array $parameters = [])
{
$data = empty($parameters) ? $_POST : $parameters;
if (empty($data) || empty($data['sign'])) {
throw new InvalidResponseException('Illegal push request.', 0, $data);
}
$string = $this->getSignContent($data, $needSignType);
if (openssl_verify($string, base64_decode($data['sign']), $this->getAliPublicKey(), OPENSSL_ALGO_SHA256) !== 1) {
throw new InvalidResponseException('Data signature verification failed.', 0, $data);
}
return $data;
}
/**
* 验证接口返回的数据签名
* @param array $data 通知数据
* @param null|string $sign 数据签名
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
protected function verify($data, $sign)
{
unset($data['sign']);
if ($this->options->get('sign_type') === 'RSA2') {
if (openssl_verify(json_encode($data, 256), base64_decode($sign), $this->getAliPublicKey(), OPENSSL_ALGO_SHA256) !== 1) {
throw new InvalidResponseException('Data signature verification failed by RSA2.');
}
} else {
if (openssl_verify(json_encode($data, 256), base64_decode($sign), $this->getAliPublicKey(), OPENSSL_ALGO_SHA1) !== 1) {
throw new InvalidResponseException('Data signature verification failed by RSA.');
}
}
return $data;
}
/**
* 获取数据签名
* @return string
*/
protected function getSign()
{
if ($this->options->get('sign_type') === 'RSA2') {
openssl_sign($this->getSignContent($this->options->get(), true), $sign, $this->getAppPrivateKey(), OPENSSL_ALGO_SHA256);
} else {
openssl_sign($this->getSignContent($this->options->get(), true), $sign, $this->getAppPrivateKey(), OPENSSL_ALGO_SHA1);
}
return base64_encode($sign);
}
/**
* 去除证书前后内容及空白
* @param string $sign
* @return string
*/
protected function trimCert($sign)
{
return preg_replace(['/\s+/', '/-{5}.*?-{5}/'], '', $sign);
}
/**
* 数据签名处理
* @param array $data 需要进行签名数据
* @param boolean $needSignType 是否需要sign_type字段
* @return string
*/
private function getSignContent(array $data, $needSignType = false)
{
list($attrs,) = [[], ksort($data)];
if (isset($data['sign'])) unset($data['sign']);
if (empty($needSignType)) unset($data['sign_type']);
foreach ($data as $key => $value) {
if ($value === '' || is_null($value)) continue;
$attrs[] = "{$key}={$value}";
}
return join('&', $attrs);
}
/**
* 数据包生成及数据签名
* @param array $options
*/
protected function applyData($options)
{
if ($this->config->get('app_cert') && $this->config->get('root_cert')) {
$this->setAppCertSnAndRootCertSn();
}
$this->options->set('biz_content', json_encode($this->params->merge($options), 256));
$this->options->set('sign', $this->getSign());
}
/**
* 请求接口并验证访问数据
* @param array $options
* @return array|boolean
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function getResult($options)
{
$this->applyData($options);
$method = str_replace('.', '_', $this->options['method']) . '_response';
$data = json_decode(Tools::get($this->gateway, $this->options->get()), true);
if (!isset($data[$method]['code']) || $data[$method]['code'] !== '10000') {
throw new InvalidResponseException(
"Error: " .
(empty($data[$method]['code']) ? '' : "{$data[$method]['msg']} [{$data[$method]['code']}]\r\n") .
(empty($data[$method]['sub_code']) ? '' : "{$data[$method]['sub_msg']} [{$data[$method]['sub_code']}]\r\n"),
$data[$method]['code'], $data
);
}
return $data[$method];
// 返回结果签名检查
// return $this->verify($data[$method], $data['sign']);
}
/**
* 生成支付HTML代码
* @return string
*/
protected function buildPayHtml()
{
$html = "<form id='alipaysubmit' name='alipaysubmit' action='{$this->gateway}' method='post'>";
foreach ($this->options->get() as $key => $value) {
$value = str_replace("'", '&apos;', $value);
$html .= "<input type='hidden' name='{$key}' value='{$value}'/>";
}
$html .= "<input type='submit' value='ok' style='display:none;'></form>";
return "{$html}<script>document.forms['alipaysubmit'].submit();</script>";
}
/**
* 获取应用私钥内容
* @return string
*/
private function getAppPrivateKey()
{
$content = wordwrap($this->trimCert($this->config->get('private_key')), 64, "\n", true);
return "-----BEGIN RSA PRIVATE KEY-----\n{$content}\n-----END RSA PRIVATE KEY-----";
}
/**
* 获取支付公钥内容
* @return string
*/
public function getAliPublicKey()
{
$cert = $this->config->get('public_key');
if (strpos(trim($cert), '-----BEGIN CERTIFICATE-----') !== false) {
$pkey = openssl_pkey_get_public($cert);
$keyData = openssl_pkey_get_details($pkey);
return trim($keyData['key']);
} else {
$content = wordwrap($this->trimCert($cert), 64, "\n", true);
return "-----BEGIN PUBLIC KEY-----\n{$content}\n-----END PUBLIC KEY-----";
}
}
/**
* 新版 从证书中提取序列号
* @param string $sign
* @return string
*/
private function getAppCertSN($sign)
{
$ssl = openssl_x509_parse($sign, true);
return md5($this->_arr2str(array_reverse($ssl['issuer'])) . $ssl['serialNumber']);
}
/**
* 新版 提取根证书序列号
* @param string $sign
* @return string|null
*/
private function getRootCertSN($sign)
{
$sn = null;
$array = explode('-----END CERTIFICATE-----', $sign);
for ($i = 0; $i < count($array) - 1; $i++) {
$ssl[$i] = openssl_x509_parse($array[$i] . '-----END CERTIFICATE-----', true);
if (strpos($ssl[$i]['serialNumber'], '0x') === 0) {
$ssl[$i]['serialNumber'] = $this->_hex2dec($ssl[$i]['serialNumberHex']);
}
if ($ssl[$i]['signatureTypeLN'] == 'sha1WithRSAEncryption' || $ssl[$i]['signatureTypeLN'] == 'sha256WithRSAEncryption') {
if ($sn == null) {
$sn = md5($this->_arr2str(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']);
} else {
$sn = $sn . '_' . md5($this->_arr2str(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']);
}
}
}
return $sn;
}
/**
* 新版 设置网关应用公钥证书SN、支付宝根证书SN
*/
protected function setAppCertSnAndRootCertSn()
{
if (!($appCert = $this->config->get('app_cert'))) {
throw new InvalidArgumentException('Missing Config -- [app_cert|app_cert_path]');
}
if (!($rootCert = $this->config->get('root_cert'))) {
throw new InvalidArgumentException('Missing Config -- [root_cert|alipay_root_path]');
}
$this->options->set('app_cert_sn', $this->getAppCertSN($appCert));
$this->options->set('alipay_root_cert_sn', $this->getRootCertSN($rootCert));
if (!$this->options->get('app_cert_sn')) {
throw new InvalidArgumentException('Missing options -- [app_cert_sn]');
}
if (!$this->options->get('alipay_root_cert_sn')) {
throw new InvalidArgumentException('Missing options -- [alipay_root_cert_sn]');
}
}
/**
* 新版 数组转字符串
* @param array $array
* @return string
*/
private function _arr2str($array)
{
$string = [];
if ($array && is_array($array)) {
foreach ($array as $key => $value) {
$string[] = $key . '=' . $value;
}
}
return join(',', $string);
}
/**
* 新版 0x转高精度数字
* @param string $hex
* @return int|string
*/
private function _hex2dec($hex)
{
list($dec, $len) = [0, strlen($hex)];
for ($i = 1; $i <= $len; $i++) {
$dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i))));
}
return $dec;
}
/**
* 应用数据操作
* @param array $options
* @return mixed
*/
abstract public function apply($options);
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Contracts;
@ -17,6 +19,7 @@ namespace WeChat\Contracts;
use WeChat\Exceptions\InvalidArgumentException;
use WeChat\Exceptions\InvalidDecryptException;
use WeChat\Exceptions\InvalidResponseException;
use WeChat\Prpcrypt\Prpcrypt;
/**
* 微信通知处理基本类
@ -43,18 +46,18 @@ class BasicPushEvent
*/
protected $encryptType;
/**
* 公众号的推送请求参数
* @var DataArray
*/
protected $input;
/**
* 当前公众号配置对象
* @var DataArray
*/
protected $config;
/**
* 公众号的推送请求参数
* @var DataArray
*/
protected $params;
/**
* 公众号推送内容对象
* @var DataArray
@ -69,10 +72,11 @@ class BasicPushEvent
/**
* BasicPushEvent constructor.
* @param array $options
* @throws InvalidResponseException
* @param array $options 配置参数
* @param boolean $showEchoStr 回显内容
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function __construct(array $options)
public function __construct(array $options, $showEchoStr = true)
{
if (empty($options['appid'])) {
throw new InvalidArgumentException("Missing Config -- [appid]");
@ -85,20 +89,17 @@ class BasicPushEvent
}
// 参数初始化
$this->config = new DataArray($options);
$this->params = new DataArray($_REQUEST);
$this->input = new DataArray($_REQUEST);
$this->appid = $this->config->get('appid');
// 推送消息处理
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$this->postxml = file_get_contents("php://input");
$this->encryptType = $this->params->get('encrypt_type');
if ($this->encryptType == 'aes') {
$this->postxml = Tools::getRawInput();
$this->encryptType = $this->input->get('encrypt_type');
if ($this->isEncrypt()) {
if (empty($options['encodingaeskey'])) {
throw new InvalidArgumentException("Missing Config -- [encodingaeskey]");
}
if (!class_exists('Prpcrypt', false)) {
require __DIR__ . '/Prpcrypt.php';
}
$prpcrypt = new \Prpcrypt($this->config->get('encodingaeskey'));
$prpcrypt = new Prpcrypt($this->config->get('encodingaeskey'));
$result = Tools::xml2arr($this->postxml);
$array = $prpcrypt->decrypt($result['Encrypt']);
if (intval($array[0]) > 0) {
@ -108,35 +109,55 @@ class BasicPushEvent
}
$this->receive = new DataArray(Tools::xml2arr($this->postxml));
} elseif ($_SERVER['REQUEST_METHOD'] == "GET" && $this->checkSignature()) {
@ob_clean();
exit($this->params->get('echostr'));
$this->receive = new DataArray([]);
if ($showEchoStr && ob_clean()) {
echo($this->input->get('echostr'));
}
} else {
throw new InvalidResponseException('Invalid interface request.', '0');
}
}
/**
* 获取回显字串
* @return string
*/
public function getEchoStr()
{
if ($_SERVER['REQUEST_METHOD'] == "GET" && $this->checkSignature()) {
return $this->input->get('echostr');
} else {
return '';
}
}
/**
* 消息是否需要加密
* @return boolean
*/
public function isEncrypt()
{
return $this->encryptType === 'aes';
}
/**
* 回复消息
* @param array $data 消息内容
* @param bool $return 是否返回XML内容
* @return string
* @throws InvalidDecryptException
* @param boolean $return 是否返回XML内容
* @param boolean $isEncrypt 是否加密内容
* @return string|void
* @throws \WeChat\Exceptions\InvalidDecryptException
*/
public function reply(array $data = [], $return = false)
public function reply(array $data = [], $return = false, $isEncrypt = false)
{
$xml = Tools::arr2xml(empty($data) ? $this->message : $data);
if ($this->encryptType == 'aes') {
if (!class_exists('Prpcrypt', false)) {
require __DIR__ . '/Prpcrypt.php';
}
$prpcrypt = new \Prpcrypt($this->config->get('encodingaeskey'));
if ($this->isEncrypt() || $isEncrypt) {
$prpcrypt = new Prpcrypt($this->config->get('encodingaeskey'));
// 如果是第三方平台,加密得使用 component_appid
$component_appid = $this->config->get('component_appid');
$appid = empty($component_appid) ? $this->appid : $component_appid;
$array = $prpcrypt->encrypt($xml, $appid);
if ($array[0] > 0) {
throw new InvalidDecryptException('Encrypt Error.', '0');
}
if ($array[0] > 0) throw new InvalidDecryptException('Encrypt Error.', '0');
list($timestamp, $encrypt) = [time(), $array[1]];
$nonce = rand(77, 999) * rand(605, 888) * rand(11, 99);
$tmpArr = [$this->config->get('token'), $timestamp, $nonce, $encrypt];
@ -145,30 +166,24 @@ class BasicPushEvent
$format = "<xml><Encrypt><![CDATA[%s]]></Encrypt><MsgSignature><![CDATA[%s]]></MsgSignature><TimeStamp>%s</TimeStamp><Nonce><![CDATA[%s]]></Nonce></xml>";
$xml = sprintf($format, $encrypt, $signature, $timestamp, $nonce);
}
if ($return) {
return $xml;
}
if ($return) return $xml;
@ob_clean();
echo $xml;
}
/**
* 验证来自微信服务器
* @param string $str
* @return bool
*/
private function checkSignature($str = '')
private function checkSignature()
{
$nonce = $this->params->get('nonce');
$timestamp = $this->params->get('timestamp');
$msg_signature = $this->params->get('msg_signature');
$signature = empty($msg_signature) ? $this->params->get('signature') : $msg_signature;
$tmpArr = [$this->config->get('token'), $timestamp, $nonce, $str];
$nonce = $this->input->get('nonce');
$timestamp = $this->input->get('timestamp');
$msg_signature = $this->input->get('msg_signature');
$signature = empty($msg_signature) ? $this->input->get('signature') : $msg_signature;
$tmpArr = [$this->config->get('token'), $timestamp, $nonce, ''];
sort($tmpArr, SORT_STRING);
if (sha1(implode($tmpArr)) == $signature) {
return true;
}
return false;
return sha1(implode($tmpArr)) === $signature;
}
/**

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Contracts;
@ -40,19 +42,25 @@ class BasicWeChat
* 当前请求方法参数
* @var array
*/
private $currentMethod = [];
protected $currentMethod = [];
/**
* 当前模式
* @var bool
*/
private $isTry = false;
protected $isTry = false;
/**
* 静态缓存
* @var static
*/
protected static $cache;
/**
* 注册代替函数
* @var string
*/
private $GetAccessTokenCallback;
protected $GetAccessTokenCallback;
/**
* BasicWeChat constructor.
@ -76,7 +84,19 @@ class BasicWeChat
}
/**
* 获取访问accessToken
* 静态创建对象
* @param array $config
* @return static
*/
public static function instance(array $config)
{
$key = md5(get_called_class() . serialize($config));
if (isset(self::$cache[$key])) return self::$cache[$key];
return self::$cache[$key] = new static($config);
}
/**
* 获取访问 AccessToken
* @return string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
@ -110,25 +130,25 @@ class BasicWeChat
/**
* 设置外部接口 AccessToken
* @param string $access_token
* @param string $accessToken
* @throws \WeChat\Exceptions\LocalCacheException
* @author 高一平 <iam@gaoyiping.com>
*
* 当用户使用自己的缓存驱动时,直接实例化对象后可直接设置 AccessToekn
* 当用户使用自己的缓存驱动时,直接实例化对象后可直接设置 AccessToken
* - 多用于分布式项目时保持 AccessToken 统一
* - 使用此方法后就由用户来保证传入的 AccessToekn 为有效 AccessToekn
* - 使用此方法后就由用户来保证传入的 AccessToken 为有效 AccessToken
*/
public function setAccessToken($access_token)
public function setAccessToken($accessToken)
{
if (!is_string($access_token)) {
if (!is_string($accessToken)) {
throw new InvalidArgumentException("Invalid AccessToken type, need string.");
}
$cache = $this->config->get('appid') . '_access_token';
Tools::setCache($cache, $this->access_token = $access_token);
Tools::setCache($cache, $this->access_token = $accessToken);
}
/**
* 清理删除accessToken
* 清理删除 AccessToken
* @return bool
*/
public function delAccessToken()
@ -142,18 +162,20 @@ class BasicWeChat
* @param string $url 接口地址
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function httpGetForJson($url)
{
try {
return Tools::json2arr(Tools::get($url));
} catch (InvalidResponseException $e) {
if (!$this->isTry && in_array($e->getCode(), ['40014', '40001', '41001', '42001'])) {
$this->delAccessToken();
$this->isTry = true;
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
} catch (InvalidResponseException $exception) {
if (isset($this->currentMethod['method']) && empty($this->isTry)) {
if (in_array($exception->getCode(), ['40014', '40001', '41001', '42001'])) {
[$this->delAccessToken(), $this->isTry = true];
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
}
}
throw new InvalidResponseException($e->getMessage(), $e->getCode());
throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
}
}
@ -161,20 +183,24 @@ class BasicWeChat
* 以POST获取接口数据并转为数组
* @param string $url 接口地址
* @param array $data 请求数据
* @param bool $buildToJson
* @param bool $toJson 转换JSON
* @param array $options 请求扩展数据
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function httpPostForJson($url, array $data, $buildToJson = true)
protected function httpPostForJson($url, array $data, $toJson = true, array $options = [])
{
try {
return Tools::json2arr(Tools::post($url, $buildToJson ? Tools::arr2json($data) : $data));
} catch (InvalidResponseException $e) {
if (!$this->isTry && in_array($e->getCode(), ['40014', '40001', '41001', '42001'])) {
$options['headers'] = isset($options['headers']) ? $options['headers'] : [];
if ($toJson) $options['headers'][] = 'Content-Type: application/json';
return Tools::json2arr(Tools::post($url, $toJson ? Tools::arr2json($data) : $data, $options));
} catch (InvalidResponseException $exception) {
if (!$this->isTry && in_array($exception->getCode(), ['40014', '40001', '41001', '42001'])) {
[$this->delAccessToken(), $this->isTry = true];
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
}
throw new InvalidResponseException($e->getMessage(), $e->getCode());
throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
}
}
@ -183,39 +209,37 @@ class BasicWeChat
* @param string $url 接口地址
* @param string $method 当前接口方法
* @param array $arguments 请求参数
* @return mixed
* @return string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function registerApi(&$url, $method, $arguments = [])
{
$this->currentMethod = ['method' => $method, 'arguments' => $arguments];
if (empty($this->access_token)) {
$this->access_token = $this->getAccessToken();
}
return $url = str_replace('ACCESS_TOKEN', $this->access_token, $url);
if (empty($this->access_token)) $this->access_token = $this->getAccessToken();
return $url = str_replace('ACCESS_TOKEN', urlencode($this->access_token), $url);
}
/**
* 接口通用POST请求方法
* @param string $url 接口URL
* @param array $data POST提交接口参数
* @param bool $isBuildJson
* @param bool $toJson 是否转换为JSON参数
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function callPostApi($url, array $data, $isBuildJson = true)
public function callPostApi($url, array $data, $toJson = true, array $options = [])
{
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data, $isBuildJson);
return $this->httpPostForJson($url, $data, $toJson, $options);
}
/**
* 接口通用GET请求方法
* @param string $url 接口URL
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function callGetApi($url)

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Contracts;
@ -22,7 +24,7 @@ use WeChat\Exceptions\InvalidResponseException;
* Class BasicPay
* @package WeChat\Contracts
*/
class BasicPay
class BasicWePay
{
/**
* 商户配置
@ -36,6 +38,11 @@ class BasicPay
*/
protected $params;
/**
* 静态缓存
* @var static
*/
protected static $cache;
/**
* WeChat constructor.
@ -72,19 +79,41 @@ class BasicPay
}
/**
* 获取微信支付通知
* @return array
* @throws InvalidResponseException
* 静态创建对象
* @param array $config
* @return static
*/
public function getNotify()
public static function instance(array $config)
{
$data = Tools::xml2arr(file_get_contents('php://input'));
$key = md5(get_called_class() . serialize($config));
if (isset(self::$cache[$key])) return self::$cache[$key];
return self::$cache[$key] = new static($config);
}
/**
* 获取微信支付通知
* @param string|array $xml
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getNotify($xml = '')
{
$data = is_array($xml) ? $xml : Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
if (isset($data['sign']) && $this->getPaySign($data) === $data['sign']) {
return $data;
}
throw new InvalidResponseException('Invalid Notify.', '0');
}
/**
* 获取微信支付通知回复内容
* @return string
*/
public function getNotifySuccessReply()
{
return Tools::arr2xml(['return_code' => 'SUCCESS', 'return_msg' => 'OK']);
}
/**
* 生成支付签名
* @param array $data 参与签名的数据
@ -96,7 +125,10 @@ class BasicPay
{
ksort($data);
if (isset($data['sign'])) unset($data['sign']);
foreach ($data as $k => $v) $buff .= "{$k}={$v}&";
foreach ($data as $k => $v) {
if ('' === $v || null === $v) continue;
$buff .= "{$k}={$v}&";
}
$buff .= ("key=" . $this->config->get('mch_key'));
if (strtoupper($signType) === 'MD5') {
return strtoupper(md5($buff));
@ -108,7 +140,7 @@ class BasicPay
* 转换短链接
* @param string $longUrl 需要转换的URL签名用原串传输需URLencode
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function shortUrl($longUrl)
@ -117,34 +149,32 @@ class BasicPay
return $this->callPostApi($url, ['long_url' => $longUrl]);
}
/**
* 数组直接转xml数据输出
* @param array $data
* @param bool $isReturn
* @return string
* @return string|void
*/
public function toXml(array $data, $isReturn = false)
{
$xml = Tools::arr2xml($data);
if ($isReturn) {
return $xml;
}
if ($isReturn) return $xml;
echo $xml;
}
/**
* Post请求接口
* Post 请求接口
* @param string $url 请求
* @param array $data 接口参数
* @param bool $isCert 是否需要使用双向证书
* @param string $signType 数据签名类型 MD5|SHA256
* @param bool $needSignType 是否需要传签名类型参数
* @param bool $needNonceStr
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function callPostApi($url, array $data, $isCert = false, $signType = 'HMAC-SHA256', $needSignType = true)
protected function callPostApi($url, array $data, $isCert = false, $signType = 'HMAC-SHA256', $needSignType = true, $needNonceStr = true)
{
$option = [];
if ($isCert) {
@ -166,7 +196,8 @@ class BasicPay
}
}
$params = $this->params->merge($data);
$needSignType && ($params['sign_type'] = strtoupper($signType));
if (!$needNonceStr) unset($params['nonce_str']);
if ($needSignType) $params['sign_type'] = strtoupper($signType);
$params['sign'] = $this->getPaySign($params, $signType);
$result = Tools::xml2arr(Tools::post($url, Tools::arr2xml($params), $option));
if ($result['return_code'] !== 'SUCCESS') {

View File

@ -0,0 +1,43 @@
<?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 WeChat\Contracts;
/**
* 企业微信基础类
* Class BasicWeWork
* @package WeChat\Contracts
*/
class BasicWeWork extends BasicWeChat
{
/**
* 获取访问 AccessToken
* @return string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getAccessToken()
{
if ($this->access_token) return $this->access_token;
$ckey = $this->config->get('appid') . '_access_token';
if ($this->access_token = Tools::getCache($ckey)) return $this->access_token;
list($appid, $secret) = [$this->config->get('appid'), $this->config->get('appsecret')];
$result = Tools::json2arr(Tools::get("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$appid}&corpsecret={$secret}"));
if (isset($result['access_token']) && $result['access_token']) Tools::setCache($ckey, $result['access_token'], 7000);
return $this->access_token = $result['access_token'];
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Contracts;
@ -51,7 +53,7 @@ class DataArray implements ArrayAccess
/**
* 获取配置项参数
* @param string|null $offset
* @return array|string|null
* @return array|string|null|mixed
*/
public function get($offset = null)
{
@ -76,7 +78,9 @@ class DataArray implements ArrayAccess
* 设置配置项值
* @param string $offset
* @param string|array|null|integer $value
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
@ -91,6 +95,7 @@ class DataArray implements ArrayAccess
* @param string $offset
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->config[$offset]);
@ -99,7 +104,9 @@ class DataArray implements ArrayAccess
/**
* 清理配置项
* @param string|null $offset
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset = null)
{
if (is_null($offset)) {
@ -112,13 +119,12 @@ class DataArray implements ArrayAccess
/**
* 获取配置项参数
* @param string|null $offset
* @return array|string|null
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset = null)
{
if (is_null($offset)) {
return $this->config;
}
if (is_null($offset)) return $this->config;
return isset($this->config[$offset]) ? $this->config[$offset] : null;
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Contracts;

View File

@ -0,0 +1,79 @@
<?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 WeChat\Contracts;
/**
* 自定义CURL文件类
* Class MyCurlFile
* @package WeChat\Contracts
*/
class MyCurlFile extends \stdClass
{
/**
* 当前数据类型
* @var string
*/
public $datatype = 'MY_CURL_FILE';
/**
* MyCurlFile constructor.
* @param string|array $filename
* @param string $mimetype
* @param string $postname
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function __construct($filename, $mimetype = '', $postname = '')
{
if (is_array($filename)) {
foreach ($filename as $k => $v) $this->{$k} = $v;
} else {
$this->mimetype = $mimetype;
$this->postname = $postname;
$this->extension = pathinfo($filename, PATHINFO_EXTENSION);
if (empty($this->extension)) $this->extension = 'tmp';
if (empty($this->mimetype)) $this->mimetype = Tools::getExtMine($this->extension);
if (empty($this->postname)) $this->postname = pathinfo($filename, PATHINFO_BASENAME);
$this->content = base64_encode(file_get_contents($filename));
$this->tempname = md5($this->content) . ".{$this->extension}";
}
}
/**
* 获取文件上传信息
* @return \CURLFile|string
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get()
{
$this->filename = Tools::pushFile($this->tempname, base64_decode($this->content));
if (class_exists('CURLFile')) {
return new \CURLFile($this->filename, $this->mimetype, $this->postname);
} else {
return "@{$this->tempname};filename={$this->postname};type={$this->mimetype}";
}
}
/**
* 通用销毁函数清理缓存文件
* 提前删除过期因此放到了网络请求之后
*/
public function __destruct()
{
// Tools::delCache($this->tempname);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Contracts;
@ -18,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
@ -31,6 +59,22 @@ class Tools
*/
public static $cache_path = null;
/**
* 缓存读写配置
* @var array
*/
public static $cache_callable = [
'set' => null, // 写入缓存 ($name,$value='',$expired=3600):string
'get' => null, // 获取缓存 ($name):mixed|null
'del' => null, // 删除缓存 ($name):boolean
'put' => null, // 写入文件 ($name,$content):string
];
/**
* 网络缓存
* @var array
*/
private static $cache_curl = [];
/**
* 产生随机字符串
@ -47,13 +91,35 @@ class Tools
return $str;
}
/**
* 获取输入对象
* @return string
*/
public static function getRawInput()
{
if (empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
return file_get_contents('php://input');
} else {
return $GLOBALS['HTTP_RAW_POST_DATA'];
}
}
/**
* 根据文件后缀获取文件MINE
* @param array $ext 文件后缀
* 设置输入内容
* @param string $rawInput
* @return void
*/
public static function setRawInput($rawInput)
{
$GLOBALS['HTTP_RAW_POST_DATA'] = $rawInput;
}
/**
* 根据文件后缀获取文件类型
* @param string|array $ext 文件后缀
* @param array $mine 文件后缀MINE信息
* @return string
* @throws LocalCacheException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public static function getExtMine($ext, $mine = [])
{
@ -65,9 +131,9 @@ class Tools
}
/**
* 获取所有文件扩展的mine
* 获取所有文件扩展的类型
* @return array
* @throws LocalCacheException
* @throws \WeChat\Exceptions\LocalCacheException
*/
private static function getMines()
{
@ -75,9 +141,7 @@ class Tools
if (empty($mines)) {
$content = file_get_contents('http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types');
preg_match_all('#^([^\s]{2,}?)\s+(.+?)$#ism', $content, $matches, PREG_SET_ORDER);
foreach ($matches as $match) foreach (explode(" ", $match[2]) as $ext) {
$mines[$ext] = $match[1];
}
foreach ($matches as $match) foreach (explode(" ", $match[2]) as $ext) $mines[$ext] = $match[1];
self::setCache('all_ext_mine', $mines);
}
return $mines;
@ -85,20 +149,24 @@ class Tools
/**
* 创建CURL文件对象
* @param $filename
* @param mixed $filename
* @param string $mimetype
* @param string $postname
* @return \CURLFile|string
* @throws LocalCacheException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public static function createCurlFile($filename, $mimetype = null, $postname = null)
{
is_null($postname) && $postname = basename($filename);
is_null($mimetype) && $mimetype = self::getExtMine(pathinfo($filename, 4));
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $mimetype, $postname);
if (is_string($filename) && file_exists($filename)) {
if (is_null($postname)) $postname = basename($filename);
if (is_null($mimetype)) $mimetype = self::getExtMine(pathinfo($filename, 4));
if (class_exists('CURLFile')) {
return new \CURLFile($filename, $mimetype, $postname);
} else {
return "@{$filename};filename={$postname};type={$mimetype}";
}
}
return "@{$filename};filename={$postname};type={$mimetype}";
return $filename;
}
/**
@ -141,29 +209,105 @@ class Tools
*/
public static function xml2arr($xml)
{
$entity = libxml_disable_entity_loader(true);
$data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
libxml_disable_entity_loader($entity);
return json_decode(self::arr2json($data), true);
if (PHP_VERSION_ID < 80000) {
$backup = libxml_disable_entity_loader(true);
$data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
libxml_disable_entity_loader($backup);
} else {
$data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
}
return json_decode(json_encode($data), true);
}
/**
* 解析XML文本内容
* @param string $xml
* @return array|false
*/
public static function xml3arr($xml)
{
$state = xml_parse($parser = xml_parser_create(), $xml, true);
return xml_parser_free($parser) && $state ? self::xml2arr($xml) : false;
}
/**
* 数组转xml内容
* @param array $data
* @return null|string|string
* @return null|string
*/
public static function arr2json($data)
{
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function ($matches) {
return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");
}, ($jsonData = json_encode($data)) == '[]' ? '{}' : $jsonData);
$json = json_encode($data, JSON_UNESCAPED_UNICODE);
return $json === '[]' ? '{}' : $json;
}
/**
* 数组对象Emoji编译处理
* @param array $data
* @return array
*/
public static function buildEnEmojiData(array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = self::buildEnEmojiData($value);
} elseif (is_string($value)) {
$data[$key] = self::emojiEncode($value);
} else {
$data[$key] = $value;
}
}
return $data;
}
/**
* 数组对象Emoji反解析处理
* @param array $data
* @return array
*/
public static function buildDeEmojiData(array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = self::buildDeEmojiData($value);
} elseif (is_string($value)) {
$data[$key] = self::emojiDecode($value);
} else {
$data[$key] = $value;
}
}
return $data;
}
/**
* Emoji原形转换为String
* @param string $content
* @return string
*/
public static function emojiEncode($content)
{
return json_decode(preg_replace_callback("/(\\\u[ed][0-9a-f]{3})/i", function ($string) {
return addslashes($string[0]);
}, json_encode($content)));
}
/**
* Emoji字符串转换为原形
* @param string $content
* @return string
*/
public static function emojiDecode($content)
{
return json_decode(preg_replace_callback('/\\\\\\\\/i', function () {
return '\\';
}, json_encode($content)));
}
/**
* 解析JSON内容到数组
* @param string $json
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public static function json2arr($json)
{
@ -182,7 +326,8 @@ class Tools
* @param string $url 访问URL
* @param array $query GET数
* @param array $options
* @return bool|string
* @return boolean|string
* @throws \WeChat\Exceptions\LocalCacheException
*/
public static function get($url, $query = [], $options = [])
{
@ -195,7 +340,8 @@ class Tools
* @param string $url 访问URL
* @param array $data POST数据
* @param array $options
* @return bool|string
* @return boolean|string
* @throws \WeChat\Exceptions\LocalCacheException
*/
public static function post($url, $data = [], $options = [])
{
@ -208,9 +354,10 @@ class Tools
* @param string $method 请求方法
* @param string $url 请求方法
* @param array $options 请求参数[headers,data,ssl_cer,ssl_key]
* @return bool|string
* @return boolean|string
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected static function doRequest($method, $url, $options = [])
public static function doRequest($method, $url, $options = [])
{
$curl = curl_init();
// GET参数设置
@ -224,34 +371,63 @@ class Tools
// POST数据设置
if (strtolower($method) === 'post') {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $options['data']);
curl_setopt($curl, CURLOPT_POSTFIELDS, self::_buildHttpData($options['data']));
}
// 证书文件设置
if (!empty($options['ssl_cer'])) {
if (file_exists($options['ssl_cer'])) {
curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLCERT, $options['ssl_cer']);
} else {
throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_cer]");
}
}
if (!empty($options['ssl_cer'])) if (file_exists($options['ssl_cer'])) {
curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLCERT, $options['ssl_cer']);
} else throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_cer]");
// 证书文件设置
if (!empty($options['ssl_key'])) {
if (file_exists($options['ssl_key'])) {
curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLKEY, $options['ssl_key']);
} else {
throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_key]");
}
}
if (!empty($options['ssl_key'])) if (file_exists($options['ssl_key'])) {
curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLKEY, $options['ssl_key']);
} else throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_key]");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
return (intval($status["http_code"]) === 200) ? $content : false;
$content = curl_exec($curl);
curl_close($curl);
// 清理 CURL 缓存文件
if (!empty(self::$cache_curl)) foreach (self::$cache_curl as $key => $file) {
Tools::delCache($file);
unset(self::$cache_curl[$key]);
}
return $content;
}
/**
* POST数据过滤处理
* @param array $data 需要处理的数据
* @param boolean $build 是否编译数据
* @return array|string
* @throws \WeChat\Exceptions\LocalCacheException
*/
private static function _buildHttpData($data, $build = true)
{
if (!is_array($data)) return $data;
foreach ($data as $key => $value) if ($value instanceof \CURLFile) {
$build = false;
} elseif (is_object($value) && isset($value->datatype) && $value->datatype === 'MY_CURL_FILE') {
$build = false;
$mycurl = new MyCurlFile((array)$value);
$data[$key] = $mycurl->get();
self::$cache_curl[] = $mycurl->tempname;
} elseif (is_array($value) && isset($value['datatype']) && $value['datatype'] === 'MY_CURL_FILE') {
$build = false;
$mycurl = new MyCurlFile($value);
$data[$key] = $mycurl->get();
self::$cache_curl[] = $mycurl->tempname;
} elseif (is_string($value) && class_exists('CURLFile', false) && stripos($value, '@') === 0) {
if (($filename = realpath(trim($value, '@'))) && file_exists($filename)) {
$build = false;
$data[$key] = self::createCurlFile($filename);
}
}
return $build ? http_build_query($data) : $data;
}
/**
@ -259,12 +435,17 @@ class Tools
* @param string $name 文件名称
* @param string $content 文件内容
* @return string
* @throws LocalCacheException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public static function pushFile($name, $content)
{
$file = self::getCacheName($name);
if (!file_put_contents($file, $content)) throw new LocalCacheException('local file write error.', '0');
if (is_callable(self::$cache_callable['put'])) {
return call_user_func_array(self::$cache_callable['put'], func_get_args());
}
$file = self::_getCacheName($name);
if (!file_put_contents($file, $content)) {
throw new LocalCacheException('local file write error.', '0');
}
return $file;
}
@ -274,13 +455,18 @@ class Tools
* @param string $value 缓存内容
* @param int $expired 缓存时间(0表示永久缓存)
* @return string
* @throws LocalCacheException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public static function setCache($name, $value = '', $expired = 3600)
{
$file = self::getCacheName($name);
$content = serialize(['name' => $name, 'value' => $value, 'expired' => time() + intval($expired)]);
if (!file_put_contents($file, $content)) throw new LocalCacheException('local cache error.', '0');
if (is_callable(self::$cache_callable['set'])) {
return call_user_func_array(self::$cache_callable['set'], func_get_args());
}
$file = self::_getCacheName($name);
$data = ['name' => $name, 'value' => $value, 'expired' => time() + intval($expired)];
if (!file_put_contents($file, serialize($data))) {
throw new LocalCacheException('local cache error.', '0');
}
return $file;
}
@ -291,8 +477,11 @@ class Tools
*/
public static function getCache($name)
{
$file = self::getCacheName($name);
if (file_exists($file) && ($content = file_get_contents($file))) {
if (is_callable(self::$cache_callable['get'])) {
return call_user_func_array(self::$cache_callable['get'], func_get_args());
}
$file = self::_getCacheName($name);
if (file_exists($file) && is_file($file) && ($content = file_get_contents($file))) {
$data = unserialize($content);
if (isset($data['expired']) && (intval($data['expired']) === 0 || intval($data['expired']) >= time())) {
return $data['value'];
@ -305,12 +494,15 @@ class Tools
/**
* 移除缓存文件
* @param string $name 缓存名称
* @return bool
* @return boolean
*/
public static function delCache($name)
{
$file = self::getCacheName($name);
return file_exists($file) ? unlink($file) : true;
if (is_callable(self::$cache_callable['del'])) {
return call_user_func_array(self::$cache_callable['del'], func_get_args());
}
$file = self::_getCacheName($name);
return !file_exists($file) || @unlink($file);
}
/**
@ -318,7 +510,7 @@ class Tools
* @param string $name
* @return string
*/
private static function getCacheName($name)
private static function _getCacheName($name)
{
if (empty(self::$cache_path)) {
self::$cache_path = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR;

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -34,56 +36,49 @@ class Custom extends BasicWeChat
*/
public function addAccount($kf_account, $nickname)
{
$data = ['kf_account' => $kf_account, 'nickname' => $nickname];
$url = "https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, ['kf_account' => $kf_account, 'nickname' => $nickname]);
}
/**
* 修改客服帐号
* @param string $kf_account 客服账号
* @param string $kfAccount 客服账号
* @param string $nickname 客服昵称
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function updateAccount($kf_account, $nickname)
public function updateAccount($kfAccount, $nickname)
{
$data = ['kf_account' => $kf_account, 'nickname' => $nickname];
$url = "https://api.weixin.qq.com/customservice/kfaccount/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, ['kf_account' => $kfAccount, 'nickname' => $nickname]);
}
/**
* 删除客服帐号
* @param string $kf_account 客服账号
* @param string $kfAccount 客服账号
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function deleteAccount($kf_account)
public function deleteAccount($kfAccount)
{
$data = ['kf_account' => $kf_account];
$url = "https://api.weixin.qq.com/customservice/kfaccount/del?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, ['kf_account' => $kfAccount]);
}
/**
* 邀请绑定客服帐号
* @param string $kf_account 完整客服帐号,格式为:帐号前缀@公众号微信号
* @param string $kfAccount 完整客服帐号,格式为:帐号前缀@公众号微信号
* @param string $invite_wx 接收绑定邀请的客服微信号
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function inviteworker($kf_account, $invite_wx)
public function inviteWorker($kfAccount, $invite_wx)
{
$url = 'https://api.weixin.qq.com/customservice/kfaccount/inviteworker?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['kf_account' => $kf_account, 'invite_wx' => $invite_wx]);
return $this->callPostApi($url, ['kf_account' => $kfAccount, 'invite_wx' => $invite_wx]);
}
/**
@ -95,8 +90,7 @@ class Custom extends BasicWeChat
public function getAccountList()
{
$url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
@ -109,9 +103,8 @@ class Custom extends BasicWeChat
*/
public function uploadHeadimg($kf_account, $image)
{
$url = "http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account={$kf_account}";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($image)]);
$url = "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account={$kf_account}";
return $this->callPostApi($url, ['media' => Tools::createCurlFile($image)], false);
}
/**
@ -124,8 +117,7 @@ class Custom extends BasicWeChat
public function send(array $data)
{
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -139,8 +131,7 @@ class Custom extends BasicWeChat
public function typing($openid, $command = 'Typing')
{
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['touser' => $openid, 'command' => $command]);
return $this->callPostApi($url, ['touser' => $openid, 'command' => $command]);
}
/**
@ -153,8 +144,7 @@ class Custom extends BasicWeChat
public function massSendAll(array $data)
{
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -167,8 +157,7 @@ class Custom extends BasicWeChat
public function massSend(array $data)
{
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -184,8 +173,7 @@ class Custom extends BasicWeChat
$data = ['msg_id' => $msg_id];
is_null($article_idx) || $data['article_idx'] = $article_idx;
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -198,22 +186,20 @@ class Custom extends BasicWeChat
public function massPreview(array $data)
{
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 查询群发消息发送状态【订阅号与服务号认证后均可用】
* @param integer $msg_id 群发消息后返回的消息id
* @param integer $msgId 群发消息后返回的消息id
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function massGet($msg_id)
public function massGet($msgId)
{
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['msg_id' => $msg_id]);
return $this->callPostApi($url, ['msg_id' => $msgId]);
}
/**
@ -225,8 +211,7 @@ class Custom extends BasicWeChat
public function massGetSeed()
{
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/speed/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, []);
return $this->callPostApi($url, []);
}
/**
@ -239,9 +224,6 @@ class Custom extends BasicWeChat
public function massSetSeed($speed)
{
$url = "https://api.weixin.qq.com/cgi-bin/message/mass/speed/set?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['speed' => $speed]);
return $this->callPostApi($url, ['speed' => $speed]);
}
}

124
WeChat/Draft.php Normal file
View File

@ -0,0 +1,124 @@
<?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 WeChat;
use WeChat\Contracts\BasicWeChat;
/**
* 微信草稿箱管理
* Class Draft
* @author taoxin
* @package WeChat
*/
class Draft extends BasicWeChat
{
/**
* 新建草稿
* @param $articles
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function add($articles)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['articles' => $articles]);
}
/**
* 获取草稿
* @param string $mediaId
* @param string $outType 返回处理函数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get($mediaId, $outType = null)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/get?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['media_id' => $mediaId]);
}
/**
* 删除草稿
* @param string $mediaId
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delete($mediaId)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/delete?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['media_id' => $mediaId]);
}
/**
* 新增图文素材
* @param array $data 文件名称
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addNews($data)
{
$url = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data);
}
/**
* 修改草稿
* @param string $media_id 要修改的图文消息的id
* @param int $index 要更新的文章在图文消息中的位置多图文消息时此字段才有意义第一篇为0
* @param $articles
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function update($media_id, $index, $articles)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/update?access_token=ACCESS_TOKEN";
$data = ['media_id' => $media_id, 'index' => $index, 'articles' => $articles];
return $this->callPostApi($url, $data);
}
/**
* 获取草稿总数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getCount()
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/count?access_token=ACCESS_TOKEN";
return $this->callGetApi($url);
}
/**
* 获取草稿列表
* @param int $offset 从全部素材的该偏移位置开始返回0表示从第一个素材返回
* @param int $count 返回素材的数量取值在1到20之间
* @param int $noContent 1 表示不返回 content 字段0 表示正常返回,默认为 0
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function batchGet($offset = 0, $count = 20, $noContent = 0)
{
$url = "https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['no_content' => $noContent, 'offset' => $offset, 'count' => $count]);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Exceptions;

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Exceptions;

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Exceptions;

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Exceptions;

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat\Exceptions;

98
WeChat/Freepublish.php Normal file
View File

@ -0,0 +1,98 @@
<?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 WeChat;
use WeChat\Contracts\BasicWeChat;
/**
* 发布能力
* Class Freepublish
* @author taoxin
* @package WeChat
*/
class Freepublish extends BasicWeChat
{
/**
* 发布接口
* 开发者需要先将图文素材以草稿的形式保存(见“草稿箱/新建草稿”,如需从已保存的草稿中选择,见“草稿箱/获取草稿列表”)
* @param mixed $mediaId 选择要发布的草稿的media_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function submit($mediaId)
{
$url = "https://api.weixin.qq.com/cgi-bin/freepublish/submit?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['media_id' => $mediaId]);
}
/**
* 发布状态轮询接口
* @param mixed $publishId
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get($publishId)
{
$url = "https://api.weixin.qq.com/cgi-bin/freepublish/get?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['publish_id' => $publishId]);
}
/**
* 删除发布
* 发布成功之后,随时可以通过该接口删除。此操作不可逆,请谨慎操作。
* @param mixed $articleId 成功发布时返回的 article_id
* @param int $index 要删除的文章在图文消息中的位置第一篇编号为1该字段不填或填0会删除全部文章
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delete($articleId, $index = 0)
{
$url = "https://api.weixin.qq.com/cgi-bin/freepublish/delete?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['article_id' => $articleId, 'index' => $index]);
}
/**
* 通过 article_id 获取已发布文章
* @param mixed $articleId 要获取的草稿的article_id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getArticle($articleId)
{
$url = "https://api.weixin.qq.com/cgi-bin/freepublish/getarticle?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['article_id' => $articleId]);
}
/**
* 获取成功发布列表
* @param int $offset 从全部素材的该偏移位置开始返回0表示从第一个素材返回
* @param int $count 返回素材的数量取值在1到20之间
* @param int $noContent 1 表示不返回 content 字段0 表示正常返回,默认为 0
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function batchGet($offset = 0, $count = 20, $noContent = 0)
{
$url = "https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['no_content' => $noContent, 'offset' => $offset, 'count' => $count]);
}
}

View File

@ -3,18 +3,19 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\BasicWeChat;
/**
@ -28,15 +29,38 @@ class Limit extends BasicWeChat
/**
* 公众号调用或第三方平台帮公众号调用对公众号的所有api调用包括第三方帮其调用次数进行清零
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function clearQuota()
{
$url = 'https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['appid' => $this->config->get('appid')]);
}
/**
* 网络检测
* @param string $action 执行的检测动作
* @param string $operator 指定平台从某个运营商进行检测
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function ping($action = 'all', $operator = 'DEFAULT')
{
$url = 'https://api.weixin.qq.com/cgi-bin/callback/check?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['action' => $action, 'check_operator' => $operator]);
}
/**
* 获取微信服务器IP地址
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getCallbackIp()
{
$url = 'https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN';
return $this->callGetApi($url);
}
}

View File

@ -3,19 +3,21 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\Tools;
use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidResponseException;
/**
@ -30,8 +32,8 @@ class Media extends BasicWeChat
* @param string $filename 文件名称
* @param string $type 媒体文件类型(image|voice|video|thumb)
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function add($filename, $type = 'image')
{
@ -39,8 +41,7 @@ class Media extends BasicWeChat
throw new InvalidResponseException('Invalid Media Type.', '0');
}
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type={$type}";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($filename)], false);
return $this->callPostApi($url, ['media' => Tools::createCurlFile($filename)], false);
}
/**
@ -48,15 +49,20 @@ class Media extends BasicWeChat
* @param string $media_id
* @param string $outType 返回处理函数
* @return array|string
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get($media_id, $outType = null)
{
$url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id={$media_id}";
$this->registerApi($url, __FUNCTION__, func_get_args());
if ($outType == 'url') return $url;
$result = Tools::get($url);
if (json_decode($result)) {
if (is_array($json = json_decode($result, true))) {
if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) {
[$this->delAccessToken(), $this->isTry = true];
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
}
return Tools::json2arr($result);
}
return is_null($outType) ? $result : $outType($result);
@ -66,14 +72,13 @@ class Media extends BasicWeChat
* 新增图文素材
* @param array $data 文件名称
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addNews($data)
{
$url = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -82,39 +87,36 @@ class Media extends BasicWeChat
* @param int $index 要更新的文章在图文消息中的位置多图文消息时此字段才有意义第一篇为0
* @param array $news 文章内容
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateNews($media_id, $index, $news)
{
$data = ['media_id' => $media_id, 'index' => $index, 'articles' => $news];
$url = "https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, ['media_id' => $media_id, 'index' => $index, 'articles' => $news]);
}
/**
* 上传图文消息内的图片获取URL
* @param string $filename
* @param mixed $filename
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function uploadImg($filename)
{
$url = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($filename)], false);
return $this->callPostApi($url, ['media' => Tools::createCurlFile($filename)], false);
}
/**
* 新增其他类型永久素材
* @param string $filename 文件名称
* @param mixed $filename 文件名称
* @param string $type 媒体文件类型(image|voice|video|thumb)
* @param array $description 包含素材的描述信息
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addMaterial($filename, $type = 'image', $description = [])
{
@ -122,8 +124,7 @@ class Media extends BasicWeChat
throw new InvalidResponseException('Invalid Media Type.', '0');
}
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type={$type}";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($filename), 'description' => Tools::arr2json($description)], false);
return $this->callPostApi($url, ['media' => Tools::createCurlFile($filename), 'description' => Tools::arr2json($description)], false);
}
/**
@ -131,15 +132,20 @@ class Media extends BasicWeChat
* @param string $media_id
* @param null|string $outType 输出类型
* @return array|string
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getMaterial($media_id, $outType = null)
{
$url = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
if ($outType == 'url') return $url;
$result = Tools::post($url, ['media_id' => $media_id]);
if (json_decode($result)) {
if (is_array($json = json_decode($result, true))) {
if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) {
[$this->delAccessToken(), $this->isTry = true];
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
}
return Tools::json2arr($result);
}
return is_null($outType) ? $result : $outType($result);
@ -147,29 +153,27 @@ class Media extends BasicWeChat
/**
* 删除永久素材
* @param string $media_id
* @param string $mediaId
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delMaterial($media_id)
public function delMaterial($mediaId)
{
$url = "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['media_id' => $media_id]);
return $this->httpPostForJson($url, ['media_id' => $mediaId]);
}
/**
* 获取素材总数
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getMaterialCount()
{
$url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
@ -178,8 +182,8 @@ class Media extends BasicWeChat
* @param int $offset
* @param int $count
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function batchGetMaterial($type = 'image', $offset = 0, $count = 20)
{
@ -187,7 +191,6 @@ class Media extends BasicWeChat
throw new InvalidResponseException('Invalid Media Type.', '0');
}
$url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['type' => $type, 'offset' => $offset, 'count' => $count]);
return $this->callPostApi($url, ['type' => $type, 'offset' => $offset, 'count' => $count]);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -27,83 +29,76 @@ class Menu extends BasicWeChat
/**
* 自定义菜单查询接口
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get()
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 自定义菜单删除接口
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delete()
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 自定义菜单创建
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create(array $data)
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 创建个性化菜单
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addConditional(array $data)
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 删除个性化菜单
* @param string $menuid
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delConditional($menuid)
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['menuid' => $menuid]);
return $this->callPostApi($url, ['menuid' => $menuid]);
}
/**
* 测试个性化菜单匹配结果
* @param string $openid
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function tryConditional($openid)
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['user_id' => $openid]);
return $this->callPostApi($url, ['user_id' => $openid]);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -40,14 +42,16 @@ class Oauth extends BasicWeChat
/**
* 通过 code 获取 AccessToken openid
* @return bool|array
* @throws Exceptions\InvalidResponseException
* @param string $code 授权Code值不传则取GET参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getOauthAccessToken()
public function getOauthAccessToken($code = '')
{
$appid = $this->config->get('appid');
$appsecret = $this->config->get('appsecret');
$code = isset($_GET['code']) ? $_GET['code'] : '';
$code = $code ? $code : (isset($_GET['code']) ? $_GET['code'] : '');
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code";
return $this->httpGetForJson($url);
}
@ -55,8 +59,9 @@ class Oauth extends BasicWeChat
/**
* 刷新AccessToken并续期
* @param string $refresh_token
* @return bool|array
* @throws Exceptions\InvalidResponseException
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getOauthRefreshToken($refresh_token)
{
@ -67,29 +72,30 @@ class Oauth extends BasicWeChat
/**
* 检验授权凭证access_token是否有效
* @param string $access_token 网页授权接口调用凭证,注意此access_token与基础支持的access_token不同
* @param string $accessToken 网页授权接口调用凭证,注意此access_token与基础支持的access_token不同
* @param string $openid 用户的唯一标识
* @return array
* @throws Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function checkOauthAccessToken($access_token, $openid)
public function checkOauthAccessToken($accessToken, $openid)
{
$url = "https://api.weixin.qq.com/sns/auth?access_token={$access_token}&openid={$openid}";
$url = "https://api.weixin.qq.com/sns/auth?access_token={$accessToken}&openid={$openid}";
return $this->httpGetForJson($url);
}
/**
* 拉取用户信息(需scope为 snsapi_userinfo)
* @param string $access_token 网页授权接口调用凭证,注意此access_token与基础支持的access_token不同
* @param string $accessToken 网页授权接口调用凭证,注意此access_token与基础支持的access_token不同
* @param string $openid 用户的唯一标识
* @param string $lang 返回国家地区语言版本zh_CN 简体zh_TW 繁体en 英语
* @return array
* @throws Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getUserInfo($access_token, $openid, $lang = 'zh_CN')
public function getUserInfo($accessToken, $openid, $lang = 'zh_CN')
{
$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang={$lang}";
$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$accessToken}&openid={$openid}&lang={$lang}";
return $this->httpGetForJson($url);
}
}

View File

@ -3,19 +3,20 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\BasicPay;
use WeChat\Exceptions\InvalidResponseException;
use WeChat\Contracts\BasicWePay;
use WePay\Bill;
use WePay\Order;
use WePay\Refund;
@ -27,21 +28,32 @@ use WePay\TransfersBank;
* Class Pay
* @package WeChat\Contracts
*/
class Pay extends BasicPay
class Pay extends BasicWePay
{
/**
* 统一下单
* @param array $options
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createOrder(array $options)
{
$pay = new Order($this->config->get());
return $pay->create($options);
return Order::instance($this->config->get())->create($options);
}
/**
* 刷卡支付
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createMicropay($options)
{
return Order::instance($this->config->get())->micropay($options);
}
/**
* 创建JsApi及H5支付参数
@ -50,8 +62,17 @@ class Pay extends BasicPay
*/
public function createParamsForJsApi($prepay_id)
{
$pay = new Order($this->config->get());
return $pay->jsapiParams($prepay_id);
return Order::instance($this->config->get())->jsapiParams($prepay_id);
}
/**
* 获取APP支付参数
* @param string $prepay_id 统一下单预支付码
* @return array
*/
public function createParamsForApp($prepay_id)
{
return Order::instance($this->config->get())->appParams($prepay_id);
}
/**
@ -61,80 +82,79 @@ class Pay extends BasicPay
*/
public function createParamsForRuleQrc($product_id)
{
$pay = new Order($this->config->get());
return $pay->qrcParams($product_id);
return Order::instance($this->config->get())->qrcParams($product_id);
}
/**
* 查询订单
* @param array $options
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryOrder(array $options)
{
$pay = new Order($this->config->get());
return $pay->query($options);
return Order::instance($this->config->get())->query($options);
}
/**
* 关闭订单
* @param string $out_trade_no 商户订单号
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function closeOrder($out_trade_no)
{
$pay = new Order($this->config->get());
return $pay->close($out_trade_no);
return Order::instance($this->config->get())->close($out_trade_no);
}
/**
* 申请退款
* @param array $options
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createRefund(array $options)
{
$pay = new Refund($this->config->get());
return $pay->create($options);
return Refund::instance($this->config->get())->create($options);
}
/**
* 查询退款
* @param array $options
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryRefund(array $options)
{
$pay = new Refund($this->config->get());
return $pay->query($options);
return Refund::instance($this->config->get())->query($options);
}
/**
* 交易保障
* @param array $options
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function report(array $options)
{
$pay = new Order($this->config->get());
return $pay->report($options);
return Order::instance($this->config->get())->report($options);
}
/**
* 授权码查询openid
* @param string $authCode 扫码支付授权码,设备读取用户微信中的条码或者二维码信息
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryAuthCode($authCode)
{
$pay = new Order($this->config->get());
return $pay->queryAuthCode($authCode);
return Order::instance($this->config->get())->queryAuthCode($authCode);
}
/**
@ -142,74 +162,72 @@ class Pay extends BasicPay
* @param array $options 静音参数
* @param null|string $outType 输出类型
* @return bool|string
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function billDownload(array $options, $outType = null)
{
$pay = new Bill($this->config->get());
return $pay->download($options, $outType);
return Bill::instance($this->config->get())->download($options, $outType);
}
/**
* 拉取订单评价数据
* @param array $options
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function billCommtent(array $options)
{
$pay = new Bill($this->config->get());
return $pay->commtent($options);
return Bill::instance($this->config->get())->comment($options);
}
/**
* 企业付款到零钱
* @param array $options
* @return array
* @throws Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createTransfers(array $options)
{
$pay = new Transfers($this->config->get());
return $pay->create($options);
return Transfers::instance($this->config->get())->create($options);
}
/**
* 查询企业付款到零钱
* @param string $partner_trade_no 商户调用企业付款API时使用的商户订单号
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryTransfers($partner_trade_no)
{
$pay = new Transfers($this->config->get());
return $pay->query($partner_trade_no);
return Transfers::instance($this->config->get())->query($partner_trade_no);
}
/**
* 企业付款到银行卡
* @param array $options
* @return array
* @throws Exceptions\LocalCacheException
* @throws Exceptions\InvalidDecryptException
* @throws Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createTransfersBank(array $options)
{
$pay = new TransfersBank($this->config->get());
return $pay->create($options);
return TransfersBank::instance($this->config->get())->create($options);
}
/**
* 商户企业付款到银行卡操作进行结果查询
* @param string $partner_trade_no 商户订单号,需保持唯一
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryTransFresBank($partner_trade_no)
{
$pay = new TransfersBank($this->config->get());
return $pay->query($partner_trade_no);
return TransfersBank::instance($this->config->get())->query($partner_trade_no);
}
}

View File

@ -3,18 +3,19 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\BasicWeChat;
/**
@ -30,15 +31,14 @@ class Product extends BasicWeChat
* @param string $keystr 商品编码内容
* @param string $status 设置发布状态。on为提交审核off为取消发布
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function modStatus($keystandard, $keystr, $status = 'on')
{
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'status' => $status];
$url = "https://api.weixin.qq.com/scan/product/modstatus?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'status' => $status];
return $this->callPostApi($url, $data);
}
/**
@ -46,15 +46,13 @@ class Product extends BasicWeChat
* @param array $openids 测试人员的openid列表
* @param array $usernames 测试人员的微信号列表
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setTestWhiteList(array $openids = [], array $usernames = [])
{
$data = ['openid' => $openids, 'username' => $usernames];
$url = "https://api.weixin.qq.com/scan/testwhitelist/set?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, ['openid' => $openids, 'username' => $usernames]);
}
/**
@ -64,16 +62,15 @@ class Product extends BasicWeChat
* @param integer $qrcode_size 二维码的尺寸整型数值代表边长像素数不填写默认值为100
* @param array $extinfo 由商户自定义传入,建议仅使用大小写字母、数字及-_().*这6个常用字符
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getQrcode($keystandard, $keystr, $qrcode_size, $extinfo = [])
{
$url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN";
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'qrcode_size' => $qrcode_size];
empty($extinfo) || $data['extinfo'] = $extinfo;
$url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -81,16 +78,15 @@ class Product extends BasicWeChat
* @param string $keystandard 商品编码标准
* @param string $keystr 商品编码内容
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getProduct($keystandard, $keystr)
{
$url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN";
$data = ['keystandard' => $keystandard, 'keystr' => $keystr];
empty($extinfo) || $data['extinfo'] = $extinfo;
$url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -100,32 +96,29 @@ class Product extends BasicWeChat
* @param null|string $status 支持按状态拉取。on为发布状态off为未发布状态check为审核中状态reject为审核未通过状态all为所有状态
* @param string $keystr 支持按部分编码内容拉取。填写该参数后,可将编码内容中包含所传参数的商品信息拉出。类似关键词搜索
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getProductList($offset, $limit = 10, $status = null, $keystr = '')
{
$url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN";
$data = ['offset' => $offset, 'limit' => $limit];
is_null($status) || $data['status'] = $status;
empty($keystr) || $data['keystr'] = $keystr;
$url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 更新商品信息
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateProduct(array $data)
{
$url = "https://api.weixin.qq.com/scan/product/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -133,29 +126,26 @@ class Product extends BasicWeChat
* @param string $keystandard 商品编码标准
* @param string $keystr 商品编码内容
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function clearProduct($keystandard, $keystr)
{
$url = "https://api.weixin.qq.com/scan/product/clear?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
return $this->callPostApi($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
}
/**
* 检查wxticket参数
* @param string $ticket
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function scanTicketCheck($ticket)
{
$url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['ticket' => $ticket]);
return $this->callPostApi($url, ['ticket' => $ticket]);
}
/**
@ -164,15 +154,13 @@ class Product extends BasicWeChat
* @param string $keystr 商品编码内容
* @param string $extinfo 调用“获取商品二维码接口”时传入的extinfo为标识参数
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function clearScanticket($keystandard, $keystr, $extinfo)
{
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'extinfo' => $extinfo];
$url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'extinfo' => $extinfo];
return $this->callPostApi($url, $data);
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace WeChat\Prpcrypt;
/**
* 仅用作类内部使用
* 不用于官方API接口的errCode码
* Class ErrorCode
*/
class ErrorCode
{
public static $OK = 0;
public static $ParseXmlError = 40002;
public static $IllegalAesKey = 40004;
public static $IllegalBuffer = 40008;
public static $EncryptAESError = 40006;
public static $DecryptAESError = 40007;
public static $EncodeBase64Error = 40009;
public static $DecodeBase64Error = 40010;
public static $GenReturnXmlError = 40011;
public static $ValidateAppidError = 40005;
public static $ComputeSignatureError = 40003;
public static $ValidateSignatureError = 40001;
public static $errCode = [
'0' => '处理成功',
'40001' => '校验签名失败',
'40002' => '解析xml失败',
'40003' => '计算签名失败',
'40004' => '不合法的AESKey',
'40005' => '校验AppID失败',
'40006' => 'AES加密失败',
'40007' => 'AES解密失败',
'40008' => '公众平台发送的xml不合法',
'40009' => 'Base64编码失败',
'40010' => 'Base64解码失败',
'40011' => '公众帐号生成回包xml失败',
];
/**
* 获取错误消息内容
* @param string $code 错误代码
* @return bool
*/
public static function getErrText($code)
{
if (isset(self::$errCode[$code])) {
return self::$errCode[$code];
}
return false;
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace WeChat\Prpcrypt;
/**
* PKCS7算法 - 加解密
* Class PKCS7Encoder
*/
class PKCS7Encoder
{
public static $blockSize = 32;
/**
* 对需要加密的明文进行填充补位
* @param string $text 需要进行填充补位操作的明文
* @return string 补齐明文字符串
*/
function encode($text)
{
$amount_to_pad = PKCS7Encoder::$blockSize - (strlen($text) % PKCS7Encoder::$blockSize);
if ($amount_to_pad == 0) {
$amount_to_pad = PKCS7Encoder::$blockSize;
}
list($pad_chr, $tmp) = [chr($amount_to_pad), ''];
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr;
}
return $text . $tmp;
}
/**
* 对解密后的明文进行补位删除
* @param string $text 解密后的明文
* @return string 删除填充补位后的明文
*/
function decode($text)
{
$pad = ord(substr($text, -1));
if ($pad < 1 || $pad > PKCS7Encoder::$blockSize) {
$pad = 0;
}
return substr($text, 0, strlen($text) - $pad);
}
}

View File

@ -3,57 +3,16 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
/**
* PKCS7算法 - 加解密
* Class PKCS7Encoder
*/
class PKCS7Encoder
{
public static $blockSize = 32;
/**
* 对需要加密的明文进行填充补位
* @param string $text 需要进行填充补位操作的明文
* @return string 补齐明文字符串
*/
function encode($text)
{
$amount_to_pad = PKCS7Encoder::$blockSize - (strlen($text) % PKCS7Encoder::$blockSize);
if ($amount_to_pad == 0) {
$amount_to_pad = PKCS7Encoder::$blockSize;
}
list($pad_chr, $tmp) = [chr($amount_to_pad), ''];
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr;
}
return $text . $tmp;
}
/**
* 对解密后的明文进行补位删除
* @param string $text 解密后的明文
* @return string 删除填充补位后的明文
*/
function decode($text)
{
$pad = ord(substr($text, -1));
if ($pad < 1 || $pad > PKCS7Encoder::$blockSize) {
$pad = 0;
}
return substr($text, 0, strlen($text) - $pad);
}
}
namespace WeChat\Prpcrypt;
/**
* 公众号消息 - 加解密
@ -88,7 +47,7 @@ class Prpcrypt
$text = $pkcEncoder->encode($random . pack("N", strlen($text)) . $text . $appid);
$encrypted = openssl_encrypt($text, 'AES-256-CBC', substr($this->key, 0, 32), OPENSSL_ZERO_PADDING, $iv);
return [ErrorCode::$OK, $encrypted];
} catch (Exception $e) {
} catch (\Exception $e) {
return [ErrorCode::$EncryptAESError, null];
}
}
@ -103,7 +62,7 @@ class Prpcrypt
try {
$iv = substr($this->key, 0, 16);
$decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', substr($this->key, 0, 32), OPENSSL_ZERO_PADDING, $iv);
} catch (Exception $e) {
} catch (\Exception $e) {
return [ErrorCode::$DecryptAESError, null];
}
try {
@ -116,7 +75,7 @@ class Prpcrypt
$len_list = unpack("N", substr($content, 0, 4));
$xml_len = $len_list[1];
return [0, substr($content, 4, $xml_len), substr($content, $xml_len + 4)];
} catch (Exception $e) {
} catch (\Exception $e) {
return [ErrorCode::$IllegalBuffer, null];
}
}
@ -137,53 +96,3 @@ class Prpcrypt
}
}
/**
* 仅用作类内部使用
* 不用于官方API接口的errCode码
* Class ErrorCode
*/
class ErrorCode
{
public static $OK = 0;
public static $ParseXmlError = 40002;
public static $IllegalAesKey = 40004;
public static $IllegalBuffer = 40008;
public static $EncryptAESError = 40006;
public static $DecryptAESError = 40007;
public static $EncodeBase64Error = 40009;
public static $DecodeBase64Error = 40010;
public static $GenReturnXmlError = 40011;
public static $ValidateAppidError = 40005;
public static $ComputeSignatureError = 40003;
public static $ValidateSignatureError = 40001;
public static $errCode = [
'0' => '处理成功',
'40001' => '校验签名失败',
'40002' => '解析xml失败',
'40003' => '计算签名失败',
'40004' => '不合法的AESKey',
'40005' => '校验AppID失败',
'40006' => 'AES加密失败',
'40007' => 'AES解密失败',
'40008' => '公众平台发送的xml不合法',
'40009' => 'Base64编码失败',
'40010' => 'Base64解码失败',
'40011' => '公众帐号生成回包xml失败',
];
/**
* 获取错误消息内容
* @param string $code 错误代码
* @return bool
*/
public static function getErrText($code)
{
if (isset(self::$errCode[$code])) {
return self::$errCode[$code];
}
return false;
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -29,8 +31,8 @@ class Qrcode extends BasicWeChat
* @param string|integer $scene 场景
* @param int $expire_seconds 有效时间
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create($scene, $expire_seconds = 0)
{
@ -46,8 +48,7 @@ class Qrcode extends BasicWeChat
$data['action_name'] = is_integer($scene) ? 'QR_LIMIT_SCENE' : 'QR_LIMIT_STR_SCENE';
}
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -57,21 +58,19 @@ class Qrcode extends BasicWeChat
*/
public function url($ticket)
{
return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={$ticket}";
return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($ticket);
}
/**
* 长链接转短链接接口
* @param string $longUrl 需要转换的长链接
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function shortUrl($longUrl)
{
$url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['action' => 'long2short', 'long_url' => $longUrl]);
return $this->callPostApi($url, ['action' => 'long2short', 'long_url' => $longUrl]);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -26,28 +28,26 @@ class Scan extends BasicWeChat
/**
* 获取商户信息
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getMerchantInfo()
{
$url = "https://api.weixin.qq.com/scan/merchantinfo/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 创建商品
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addProduct(array $data)
{
$url = "https://api.weixin.qq.com/scan/product/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -56,15 +56,14 @@ class Scan extends BasicWeChat
* @param string $keystr 商品编码内容
* @param string $status 设置发布状态。on为提交审核off为取消发布
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function modProduct($keystandard, $keystr, $status = 'on')
{
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'status' => $status];
$url = "https://api.weixin.qq.com/scan/product/modstatus?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'status' => $status];
return $this->callPostApi($url, $data);
}
/**
@ -72,15 +71,13 @@ class Scan extends BasicWeChat
* @param array $openids 测试人员的openid列表
* @param array $usernames 测试人员的微信号列表
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setTestWhiteList($openids = [], $usernames = [])
{
$data = ['openid' => $openids, 'username' => $usernames];
$url = "https://api.weixin.qq.com/scan/product/modstatus?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, ['openid' => $openids, 'username' => $usernames]);
}
/**
@ -90,16 +87,15 @@ class Scan extends BasicWeChat
* @param null|string $extinfo
* @param integer $qrcode_size
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getQrc($keystandard, $keystr, $extinfo = null, $qrcode_size = 64)
{
$url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN";
$data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'qrcode_size' => $qrcode_size];
is_null($extinfo) || $data['extinfo'] = $extinfo;
$url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -107,14 +103,13 @@ class Scan extends BasicWeChat
* @param string $keystandard 商品编码标准
* @param string $keystr 商品编码内容
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getProductInfo($keystandard, $keystr)
{
$url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
return $this->callPostApi($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
}
/**
@ -124,31 +119,29 @@ class Scan extends BasicWeChat
* @param string $status 支持按状态拉取。on为发布状态off为未发布状态check为审核中状态reject为审核未通过状态all为所有状态。
* @param string $keystr 支持按部分编码内容拉取。填写该参数后,可将编码内容中包含所传参数的商品信息拉出。类似关键词搜索。
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getProductList($offset = 1, $limit = 10, $status = null, $keystr = null)
{
$url = "https://api.weixin.qq.com/scan/product/getlist?access_token=ACCESS_TOKEN";
$data = ['offset' => $offset, 'limit' => $limit];
is_null($status) || $data['status'] = $status;
is_null($keystr) || $data['keystr'] = $keystr;
$url = "https://api.weixin.qq.com/scan/product/getlist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 更新商品信息
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateProduct(array $data)
{
$url = "https://api.weixin.qq.com/scan/product/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -156,28 +149,26 @@ class Scan extends BasicWeChat
* @param string $keystandard 商品编码标准
* @param string $keystr 商品编码内容
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function clearProduct($keystandard, $keystr)
{
$url = "https://api.weixin.qq.com/scan/product/clear?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
return $this->callPostApi($url, ['keystandard' => $keystandard, 'keystr' => $keystr]);
}
/**
* 检查wxticket参数
* @param string $ticket
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function checkTicket($ticket)
{
$url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['ticket' => $ticket]);
return $this->callPostApi($url, ['ticket' => $ticket]);
}
/**
@ -186,14 +177,12 @@ class Scan extends BasicWeChat
* @param string $keystr 商品编码内容
* @param string $extinfo 调用“获取商品二维码接口”时传入的extinfo为标识参数
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function clearScanTicket($keystandard, $keystr, $extinfo)
{
$url = "https://api.weixin.qq.com/scan/scanticket/check?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['keystandard' => $keystandard, 'keystr' => $keystr, 'extinfo' => $extinfo]);
return $this->callPostApi($url, ['keystandard' => $keystandard, 'keystr' => $keystr, 'extinfo' => $extinfo]);
}
}

View File

@ -3,19 +3,21 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\Tools;
use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidResponseException;
/**
@ -44,8 +46,8 @@ class Script extends BasicWeChat
* @param string $type TICKET类型(wx_card|jsapi)
* @param string $appid 强制指定有效APPID
* @return string
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getTicket($type = 'jsapi', $appid = null)
{
@ -60,7 +62,7 @@ class Script extends BasicWeChat
throw new InvalidResponseException('Invalid Resoponse Ticket.', '0');
}
$ticket = $result['ticket'];
Tools::setCache($cache_name, $ticket, 5000);
Tools::setCache($cache_name, $ticket, 7000);
}
return $ticket;
}
@ -70,15 +72,23 @@ class Script extends BasicWeChat
* @param string $url 网页的URL
* @param string $appid 用于多个appid时使用(可空)
* @param string $ticket 强制指定ticket
* @param array $jsApiList 需初始化的 jsApiList
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getJsSign($url, $appid = null, $ticket = null)
public function getJsSign($url, $appid = null, $ticket = null, $jsApiList = null)
{
list($url,) = explode('#', $url);
is_null($ticket) && $ticket = $this->getTicket('jsapi');
is_null($appid) && $appid = $this->config->get('appid');
is_null($jsApiList) && $jsApiList = [
'updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone',
'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice',
'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'translateVoice', 'getNetworkType', 'openLocation', 'getLocation',
'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem',
'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard',
];
$data = ["url" => $url, "timestamp" => '' . time(), "jsapi_ticket" => $ticket, "noncestr" => Tools::createNoncestr(16)];
return [
'debug' => false,
@ -86,17 +96,7 @@ class Script extends BasicWeChat
"nonceStr" => $data['noncestr'],
"timestamp" => $data['timestamp'],
"signature" => $this->getSignature($data, 'sha1'),
'jsApiList' => [
'onWXDeviceBluetoothStateChange', 'onWXDeviceStateChange',
'openProductSpecificView', 'addCard', 'chooseCard', 'openCard',
'translateVoice', 'getNetworkType', 'openLocation', 'getLocation',
'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone',
'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'closeWindow', 'scanQRCode', 'chooseWXPay',
'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem',
'startScanWXDevice', 'stopScanWXDevice', 'onWXDeviceBindStateChange', 'onScanWXDeviceResult', 'onReceiveDataFromWXDevice',
'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice',
'openWXDeviceLib', 'closeWXDeviceLib', 'getWXDeviceInfos', 'sendDataToWXDevice', 'disconnectWXDevice', 'getWXDeviceTicket', 'connectWXDevice',
],
'jsApiList' => $jsApiList,
];
}
@ -104,18 +104,14 @@ class Script extends BasicWeChat
* 数据生成签名
* @param array $data 签名数组
* @param string $method 签名方法
* @param array $params 签名参数
* @return bool|string 签名值
*/
protected function getSignature($data, $method = "sha1")
protected function getSignature($data, $method = "sha1", $params = [])
{
if (!function_exists($method)) {
return false;
}
ksort($data);
$params = [];
foreach ($data as $key => $value) {
$params[] = "{$key}={$value}";
}
if (!function_exists($method)) return false;
foreach ($data as $k => $v) $params[] = "{$k}={$v}";
return $method(join('&', $params));
}
}

View File

@ -3,20 +3,21 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\Tools;
use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
/**
* 揺一揺周边
@ -29,27 +30,25 @@ class Shake extends BasicWeChat
* 申请开通功能
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function register(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/account/register?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 查询审核状态
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function auditStatus()
{
$url = "https://api.weixin.qq.com/shakearound/account/auditstatus?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
@ -59,8 +58,8 @@ class Shake extends BasicWeChat
* @param null|string $comment 备注不超过15个汉字或30个英文字母
* @param null|string $poi_id 设备关联的门店ID关联门店后在门店1KM的范围内有优先摇出信息的机会。
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createApply($quantity, $apply_reason, $comment = null, $poi_id = null)
{
@ -68,120 +67,111 @@ class Shake extends BasicWeChat
is_null($poi_id) || $data['poi_id'] = $poi_id;
is_null($comment) || $data['comment'] = $comment;
$url = "https://api.weixin.qq.com/shakearound/device/applyid?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 查询设备ID申请审核状态
* @param integer $applyId 批次ID申请设备ID时所返回的批次ID
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getApplyStatus($applyId)
{
$url = "https://api.weixin.qq.com/shakearound/device/applyid?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['apply_id' => $applyId]);
return $this->callPostApi($url, ['apply_id' => $applyId]);
}
/**
* 编辑设备信息
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateApply(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/device/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 配置设备与门店的关联关系
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function bindLocation(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/device/bindlocation?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 查询设备列表
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function search(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/device/search?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 页面管理
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createPage(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/page/add?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 编辑页面信息
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updatePage(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/page/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 查询页面列表
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function searchPage(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/page/search?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 删除页面
* @param integer page_id 指定页面的id
* @param integer $pageId 指定页面的id
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function deletePage($page_id)
public function deletePage($pageId)
{
$url = "https://api.weixin.qq.com/shakearound/page/delete?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['page_id' => $page_id]);
return $this->callPostApi($url, ['page_id' => $pageId]);
}
/**
@ -189,116 +179,108 @@ class Shake extends BasicWeChat
* @param string $filename 图片名字
* @param string $type Icon摇一摇页面展示的icon图License申请开通摇一摇周边功能时需上传的资质文件若不传type则默认type=icon
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function upload($filename, $type = 'icon')
{
$url = "https://api.weixin.qq.com/shakearound/material/add?access_token=ACCESS_TOKEN&type={$type}";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($filename)]);
return $this->callPostApi($url, ['media' => Tools::createCurlFile($filename)], false);
}
/**
* 配置设备与页面的关联关系
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function bindPage(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/device/bindpage?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 查询设备与页面的关联关系
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryPage(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/relation/search?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 以设备为维度的数据统计接口
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function totalDevice(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/statistics/device?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 批量查询设备统计数据接口
* @param integer $date 指定查询日期时间戳,单位为秒
* @param integer $page_index 指定查询的结果页序号返回结果按摇周边人数降序排序每50条记录为一页
* @param integer $pageIndex 指定查询的结果页序号返回结果按摇周边人数降序排序每50条记录为一页
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function totalDeviceList($date, $page_index = 1)
public function totalDeviceList($date, $pageIndex = 1)
{
$url = "https://api.weixin.qq.com/shakearound/statistics/devicelist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['date' => $date, 'page_index' => $page_index]);
return $this->callPostApi($url, ['date' => $date, 'page_index' => $pageIndex]);
}
/**
* 以页面为维度的数据统计接口
* @param integer $page_id 指定页面的设备ID
* @param integer $begin_date 起始日期时间戳最长时间跨度为30天单位为秒
* @param integer $end_date 结束日期时间戳最长时间跨度为30天单位为秒
* @param integer $pageId 指定页面的设备ID
* @param integer $beginDate 起始日期时间戳最长时间跨度为30天单位为秒
* @param integer $endDate 结束日期时间戳最长时间跨度为30天单位为秒
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function totalPage($page_id, $begin_date, $end_date)
public function totalPage($pageId, $beginDate, $endDate)
{
$url = "https://api.weixin.qq.com/shakearound/statistics/page?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['page_id' => $page_id, 'begin_date' => $begin_date, 'end_date' => $end_date]);
return $this->callPostApi($url, ['page_id' => $pageId, 'begin_date' => $beginDate, 'end_date' => $endDate]);
}
/**
* 编辑分组信息
* @param integer $group_id 分组唯一标识,全局唯一
* @param string $group_name 分组名称不超过100汉字或200个英文字母
* @param integer $groupId 分组唯一标识,全局唯一
* @param string $groupName 分组名称不超过100汉字或200个英文字母
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateGroup($group_id, $group_name)
public function updateGroup($groupId, $groupName)
{
$url = "https://api.weixin.qq.com/shakearound/device/group/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['group_id' => $group_id, 'group_name' => $group_name]);
return $this->callPostApi($url, ['group_id' => $groupId, 'group_name' => $groupName]);
}
/**
* 删除分组
* @param integer $group_id 分组唯一标识,全局唯一
* @param integer $groupId 分组唯一标识,全局唯一
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function deleteGroup($group_id)
public function deleteGroup($groupId)
{
$url = "https://api.weixin.qq.com/shakearound/device/group/delete?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['group_id' => $group_id]);
return $this->callPostApi($url, ['group_id' => $groupId]);
}
/**
@ -306,14 +288,13 @@ class Shake extends BasicWeChat
* @param integer $begin 分组列表的起始索引值
* @param integer $count 待查询的分组数量不能超过1000个
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGroupList($begin = 0, $count = 10)
{
$url = "https://api.weixin.qq.com/shakearound/device/group/getlist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['begin' => $begin, 'count' => $count]);
return $this->callPostApi($url, ['begin' => $begin, 'count' => $count]);
}
@ -323,42 +304,38 @@ class Shake extends BasicWeChat
* @param integer $begin 分组里设备的起始索引值
* @param integer $count 待查询的分组里设备的数量不能超过1000个
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGroupDetail($group_id, $begin = 0, $count = 100)
{
$url = "https://api.weixin.qq.com/shakearound/device/group/getdetail?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['group_id' => $group_id, 'begin' => $begin, 'count' => $count]);
return $this->callPostApi($url, ['group_id' => $group_id, 'begin' => $begin, 'count' => $count]);
}
/**
* 添加设备到分组
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addDeviceGroup(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/device/group/adddevice?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
* 从分组中移除设备
* @param array $data
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function deleteDeviceGroup(array $data)
{
$url = "https://api.weixin.qq.com/shakearound/device/group/deletedevice?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -31,8 +33,7 @@ class Tags extends BasicWeChat
public function getTags()
{
$url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
@ -45,8 +46,7 @@ class Tags extends BasicWeChat
public function createTags($name)
{
$url = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['tag' => ['name' => $name]]);
return $this->callPostApi($url, ['tag' => ['name' => $name]]);
}
/**
@ -60,8 +60,7 @@ class Tags extends BasicWeChat
public function updateTags($id, $name)
{
$url = "https://api.weixin.qq.com/cgi-bin/tags/update?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['tag' => ['name' => $name, 'id' => $id]]);
return $this->callPostApi($url, ['tag' => ['name' => $name, 'id' => $id]]);
}
/**
@ -74,8 +73,7 @@ class Tags extends BasicWeChat
public function deleteTags($tagId)
{
$url = 'https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['tag' => ['id' => $tagId]]);
return $this->callPostApi($url, ['tag' => ['id' => $tagId]]);
}
/**
@ -89,8 +87,7 @@ class Tags extends BasicWeChat
public function batchTagging(array $openids, $tagId)
{
$url = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['openid_list' => $openids, 'tagid' => $tagId]);
return $this->callPostApi($url, ['openid_list' => $openids, 'tagid' => $tagId]);
}
/**
@ -104,8 +101,7 @@ class Tags extends BasicWeChat
public function batchUntagging(array $openids, $tagId)
{
$url = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['openid_list' => $openids, 'tagid' => $tagId]);
return $this->callPostApi($url, ['openid_list' => $openids, 'tagid' => $tagId]);
}
/**
@ -118,7 +114,6 @@ class Tags extends BasicWeChat
public function getUserTagId($openid)
{
$url = 'https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['openid' => $openid]);
return $this->callPostApi($url, ['openid' => $openid]);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -25,17 +27,16 @@ class Template extends BasicWeChat
{
/**
* 设置所属行业
* @param string $industry_id1 公众号模板消息所属行业编号
* @param string $industry_id2 公众号模板消息所属行业编号
* @param string $industryId1 公众号模板消息所属行业编号
* @param string $industryId2 公众号模板消息所属行业编号
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function setIndustry($industry_id1, $industry_id2)
public function setIndustry($industryId1, $industryId2)
{
$url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['industry_id1' => $industry_id1, 'industry_id2' => $industry_id2]);
return $this->callPostApi($url, ['industry_id1' => $industryId1, 'industry_id2' => $industryId2]);
}
/**
@ -47,22 +48,21 @@ class Template extends BasicWeChat
public function getIndustry()
{
$url = "https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 获得模板ID
* @param string $tpl_id 板库中模板的编号有“TM**”和“OPENTMTM**”等形式
* @param string $templateIdShort 板库中模板的编号有“TM**”和“OPENTMTM**”等形式
* @param array $keywordNameList 选用的类目模板的关键词
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function addTemplate($tpl_id)
public function addTemplate($templateIdShort, $keywordNameList = [])
{
$url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['template_id_short' => $tpl_id]);
return $this->callPostApi($url, ['template_id_short' => $templateIdShort, 'keyword_name_list' => $keywordNameList]);
}
/**
@ -74,22 +74,20 @@ class Template extends BasicWeChat
public function getAllPrivateTemplate()
{
$url = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 删除模板ID
* @param string $tpl_id 公众帐号下模板消息ID
* @param string $tplId 公众帐号下模板消息ID
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function delPrivateTemplate($tpl_id)
public function delPrivateTemplate($tplId)
{
$url = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['template_id' => $tpl_id]);
return $this->callPostApi($url, ['template_id' => $tplId]);
}
/**
@ -102,9 +100,6 @@ class Template extends BasicWeChat
public function send(array $data)
{
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
@ -35,8 +37,7 @@ class User extends BasicWeChat
public function updateMark($openid, $remark)
{
$url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['openid' => $openid, 'remark' => $remark]);
return $this->callPostApi($url, ['openid' => $openid, 'remark' => $remark]);
}
/**
@ -49,9 +50,8 @@ class User extends BasicWeChat
*/
public function getUserInfo($openid, $lang = 'zh_CN')
{
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid={$openid}&lang=zh_CN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid={$openid}&lang={$lang}";
return $this->callGetApi($url);
}
/**
@ -69,8 +69,7 @@ class User extends BasicWeChat
foreach ($openids as $openid) {
$data['user_list'][] = ['openid' => $openid, 'lang' => $lang];
}
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, $data);
return $this->callPostApi($url, $data);
}
/**
@ -83,22 +82,34 @@ class User extends BasicWeChat
public function getUserList($next_openid = '')
{
$url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid={$next_openid}";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpGetForJson($url);
return $this->callGetApi($url);
}
/**
* 获取公众号的黑名单列表
* @param string $begin_openid
* 获取标签下粉丝列表
* @param integer $tagid 标签ID
* @param string $nextOpenid 第一个拉取的OPENID
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getBlackList($begin_openid = '')
public function getUserListByTag($tagid, $nextOpenid = '')
{
$url = 'https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['tagid' => $tagid, 'next_openid' => $nextOpenid]);
}
/**
* 获取公众号的黑名单列表
* @param string $beginOpenid
* @return array
* @throws Exceptions\InvalidResponseException
* @throws Exceptions\LocalCacheException
*/
public function getBlackList($beginOpenid = '')
{
$url = "https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['begin_openid' => $begin_openid]);
return $this->callPostApi($url, ['begin_openid' => $beginOpenid]);
}
/**
@ -111,8 +122,7 @@ class User extends BasicWeChat
public function batchBlackList(array $openids)
{
$url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['openid_list' => $openids]);
return $this->callPostApi($url, ['openid_list' => $openids]);
}
/**
@ -125,8 +135,6 @@ class User extends BasicWeChat
public function batchUnblackList(array $openids)
{
$url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['openid_list' => $openids]);
return $this->callPostApi($url, ['openid_list' => $openids]);
}
}

View File

@ -3,18 +3,19 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeChat;
use WeChat\Contracts\BasicWeChat;
/**

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
@ -18,6 +20,7 @@ use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidDecryptException;
use WeChat\Exceptions\InvalidResponseException;
use WXBizDataCrypt;
/**
@ -33,12 +36,12 @@ class Crypt extends BasicWeChat
* @param string $iv
* @param string $sessionKey
* @param string $encryptedData
* @return bool
* @return bool|array
*/
public function decode($iv, $sessionKey, $encryptedData)
{
require_once __DIR__ . DIRECTORY_SEPARATOR . 'crypt' . DIRECTORY_SEPARATOR . 'wxBizDataCrypt.php';
$pc = new \WXBizDataCrypt($this->config->get('appid'), $sessionKey);
$pc = new WXBizDataCrypt($this->config->get('appid'), $sessionKey);
$errCode = $pc->decryptData($encryptedData, $iv, $data);
if ($errCode == 0) {
return json_decode($data, true);
@ -50,6 +53,7 @@ class Crypt extends BasicWeChat
* 登录凭证校验
* @param string $code 登录时获取的 code
* @return array
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function session($code)
{
@ -65,8 +69,9 @@ class Crypt extends BasicWeChat
* @param string $iv 加密算法的初始向量
* @param string $encryptedData 加密数据( encryptedData )
* @return array
* @throws InvalidDecryptException
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function userInfo($code, $iv, $encryptedData)
{
@ -76,8 +81,42 @@ class Crypt extends BasicWeChat
}
$userinfo = $this->decode($iv, $result['session_key'], $encryptedData);
if (empty($userinfo)) {
throw new InvalidDecryptException('用户信息解析失败', 403);
throw new InvalidDecryptException('用户信息解析失败', 403);
}
return array_merge($result, $userinfo);
}
/**
* 通过授权码换取手机号
* @param string $code
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getPhoneNumber($code)
{
$url = 'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->httpPostForJson($url, ['code' => $code], true);
}
/**
* 用户支付完成后,获取该用户的 UnionId
* @param string $openid 支付用户唯一标识
* @param null|string $transaction_id 微信支付订单号
* @param null|string $mch_id 微信支付分配的商户号,和商户订单号配合使用
* @param null|string $out_trade_no 微信支付商户订单号,和商户号配合使用
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getPaidUnionId($openid, $transaction_id = null, $mch_id = null, $out_trade_no = null)
{
$url = "https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid={$openid}";
if (is_null($mch_id)) $url .= "&mch_id={$mch_id}";
if (is_null($out_trade_no)) $url .= "&out_trade_no={$out_trade_no}";
if (is_null($transaction_id)) $url .= "&transaction_id={$transaction_id}";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callGetApi($url);
}
}

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);
}
}

172
WeMini/Delivery.php Normal file
View File

@ -0,0 +1,172 @@
<?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 Delivery
* @package WeMini
*/
class Delivery extends BasicWeChat
{
/**
* 异常件退回商家商家确认收货接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function abnormalConfirm($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/confirm_return?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 addOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/add?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 addTip($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/addtips?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 cancelOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/cancel?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 getAllImmeDelivery($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/delivery/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 getBindAccount($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/shop/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 getOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/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 mockUpdateOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/test_update_order?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 preAddOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/pre_add?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 preCancelOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/precancel?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 reOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/local/business/order/readd?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

527
WeMini/Guide.php Normal file
View File

@ -0,0 +1,527 @@
<?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 Guide
* @package WeMini
*/
class Guide extends BasicWeChat
{
/**
* 服务号添加导购
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addGuideAcct($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/addguideacct?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 delGuideAcct($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/delguideacct?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 getGuideAcct($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguideacct?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取服务号的敏感词信息与自动回复信息
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideAcctConfig()
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguideacctconfig?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, [], true);
}
/**
* 服务号拉取导购列表
* @param integer $page
* @param integer $num
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideAcctList($page = 0, $num = 10)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguideacctconfig?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['page' => $page, 'num' => $num], true);
}
/**
* 获取导购聊天记录
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideBuyerChatRecord($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguideacct?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 getGuideConfig($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguideconfig?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 guideCreateQrCode($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/guidecreateqrcode?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 pushShowWxaPathMenu($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/pushshowwxapathmenu?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 setGuideAcctConfig($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/setguideacctconfig?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 setGuideConfig($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/setguideconfig?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 updateGuideAcct($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/setguideconfig?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 addGuideBuyerDisplayTag($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/addguidebuyerdisplaytag?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 addGuideBuyerTag($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/addguidebuyertag?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 addGuideTagOption($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/addguidetagoption?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 delGuideBuyerTag($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/delguidebuyertag?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 getGuideBuyerDisplayTag($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidebuyerdisplaytag?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 getGuideBuyerTag($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidebuyertag?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 查询标签可选值信息
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideTagOption()
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidetagoption?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, [], true);
}
/**
* 新建可查询标签类型,支持新建4类可查询标签
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function newGuideTagOption($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/newguidetagoption?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 queryGuideBuyerByTag($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/queryguidebuyerbytag?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 为服务号导购添加粉丝
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addGuideBuyerRelation($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/addguidebuyerrelation?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 删除导购的粉丝
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delGuideBuyerRelation($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/delguidebuyerrelation?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 查询某一个粉丝与导购的绑定关系
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideBuyerRelation($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidebuyerrelation?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 通过粉丝信息查询该粉丝与导购的绑定关系
* @param string $openid
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideBuyerRelationByBuyer($openid)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidebuyerrelation?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['openid' => $openid], true);
}
/**
* 拉取导购的粉丝列表
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideBuyerRelationList($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidebuyerrelationlist?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 将粉丝从一个导购迁移到另外一个导购下
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function rebindGuideAcctForBuyer($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/rebindguideacctforbuyer?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 更新粉丝昵称
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updateGuideBuyerRelation($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/updateguidebuyerrelation?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 删除小程序卡片素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delGuideCardMaterial($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/delguidecardmaterial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 删除图片素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delGuideImageMaterial($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/delguideimagematerial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 删除文字素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delGuideWordMaterial($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/delguidewordmaterial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 获取小程序卡片素材信息
* @param integer $type
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideCardMaterial($type = 0)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidecardmaterial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['type' => $type], true);
}
/**
* 获取图片素材信息
* @param integer $type 操作类型
* @param integer $start 分页查询,起始位置
* @param integer $num 分页查询,查询个数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideImageMaterial($type = 0, $start = 0, $num = 10)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguideimagematerial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['type' => $type, 'start' => $start, 'num' => $num], true);
}
/**
* 获取文字素材信息
* @param integer $type 操作类型
* @param integer $start 分页查询,起始位置
* @param integer $num 分页查询,查询个数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getGuideWordMaterial($type = 0, $start = 0, $num = 10)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguidewordmaterial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['type' => $type, 'start' => $start, 'num' => $num], true);
}
/**
* 添加小程序卡片素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setGuideCardMaterial($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/setguidecardmaterial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 添加图片素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setGuideImageMaterial($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/setguideimagematerial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
/**
* 为服务号添加文字素材
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setGuideWordMaterial($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/setguidewordmaterial?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
}

70
WeMini/Image.php Normal file
View File

@ -0,0 +1,70 @@
<?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 Image
* @package WeMini
*/
class Image extends BasicWeChat
{
/**
* 本接口提供基于小程序的图片智能裁剪能力
* @param string $img_url 要检测的图片 url传这个则不用传 img 参数。
* @param string $img form-data 中媒体文件标识有filename、filelength、content-type等信息传这个则不用穿 img_url
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function aiCrop($img_url, $img)
{
$url = "https://api.weixin.qq.com/cv/img/aicrop?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
}
/**
* 本接口提供基于小程序的条码/二维码识别的API
* @param string $img_url 要检测的图片 url传这个则不用传 img 参数。
* @param string $img form-data 中媒体文件标识有filename、filelength、content-type等信息传这个则不用穿 img_url
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function scanQRCode($img_url, $img)
{
$url = "https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
}
/**
* 本接口提供基于小程序的图片高清化能力
* @param string $img_url 要检测的图片 url传这个则不用传 img 参数
* @param string $img form-data 中媒体文件标识有filename、filelength、content-type等信息传这个则不用穿 img_url
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function superresolution($img_url, $img)
{
$url = "https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOKEN";
return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
}
}

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);
}
}

518
WeMini/Live.php Normal file
View File

@ -0,0 +1,518 @@
<?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 Live
* @package WeMini
*/
class Live extends BasicWeChat
{
/**
* 创建直播间
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create($data)
{
$url = 'https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取直播房间列表
* @param integer $start 起始拉取房间
* @param integer $limit 每次拉取的个数上限
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getLiveList($start = 0, $limit = 10)
{
$url = 'https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['start' => $start, 'limit' => $limit], true);
}
/**
* 获取回放源视频
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getLiveInfo($data = [])
{
$url = 'https://api.weixin.qq.com/wxa/business/getliveinfo?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 addLiveGoods($data = [])
{
$url = 'https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods?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 addGoods($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add?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 resetAuditGoods($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit?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 auditGoods($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/audit?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 deleteGoods($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?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 updateGoods($data)
{
$url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/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 stateGoods($data)
{
$url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 获取商品列表
* @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 delLive($data)
{
$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);
}
}

237
WeMini/Logistics.php Normal file
View File

@ -0,0 +1,237 @@
<?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 Logistics
* @package WeMini
*/
class Logistics extends BasicWeChat
{
/**
* 生成运单
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/order/add?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 cancelOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/order/cancel?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取支持的快递公司列表
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getAllDelivery()
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/delivery/getall?access_token=ACCESS_TOKEN';
return $this->callGetApi($url);
}
/**
* 获取运单数据
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/order/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 getPath($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取打印员。若需要使用微信打单 PC 软件,才需要调用
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getPrinter()
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/printer/getall?access_token=ACCESS_TOKEN';
return $this->callGetApi($url);
}
/**
* 获取电子面单余额。仅在使用加盟类快递公司时,才可以调用
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getQuota($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/quota/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 testUpdateOrder($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/test_update_order?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 配置面单打印员,若需要使用微信打单 PC 软件,才需要调用
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function updatePrinter($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/business/printer/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 getContact($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/delivery/contact/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 previewTemplate($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/delivery/template/preview?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 updateBusiness($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/express/delivery/service/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 updatePath($data)
{
$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);
}
}

66
WeMini/Message.php Normal file
View File

@ -0,0 +1,66 @@
<?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 Message
* @package WeMini
*/
class Message extends BasicWeChat
{
/**
* 动态消息,创建被分享动态消息的 activity_id
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createActivityId($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?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 setUpdatableMsg($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/updatablemsg/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 uniformSend($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

145
WeMini/Newtmpl.php Normal file
View File

@ -0,0 +1,145 @@
<?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 Mini
* @package WeChat
*/
class Newtmpl extends BasicWeChat
{
/**
* 获取小程序账号的类目
* @param array $data 类目信息列表
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addCategory($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/addcategory?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 获取小程序账号的类目
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getCategory()
{
$url = 'https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=ACCESS_TOKEN';
return $this->callGetApi($url);
}
/**
* 获取小程序账号的类目
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function deleteCategory()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/deletecategory?access_token=TOKEN';
return $this->callPostApi($url, [], true);
}
/**
* 获取帐号所属类目下的公共模板标题
* @param string $ids 类目 id多个用逗号隔开
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getPubTemplateTitleList($ids)
{
$url = 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=ACCESS_TOKEN';
$url .= '&' . http_build_query(['ids' => $ids, 'start' => '0', 'limit' => '30']);
return $this->callGetApi($url);
}
/**
* 获取模板标题下的关键词列表
* @param string $tid 模板标题 id可通过接口获取
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getPubTemplateKeyWordsById($tid)
{
$url = 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=ACCESS_TOKEN';
$url .= '&' . http_build_query(['tid' => $tid]);
return $this->callGetApi($url);
}
/**
* 组合模板并添加至帐号下的个人模板库
* @param string $tid 模板标题 id可通过接口获取也可登录小程序后台查看获取
* @param array $kidList 开发者自行组合好的模板关键词列表,关键词顺序可以自由搭配(例如 [3,5,4] [4,5,3]最多支持5个最少2个关键词组合
* @param string $sceneDesc 服务场景描述15个字以内
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addTemplate($tid, array $kidList, $sceneDesc = '')
{
$url = 'https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['tid' => $tid, 'kidList' => $kidList, 'sceneDesc' => $sceneDesc], false);
}
/**
* 获取当前帐号下的个人模板列表
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getTemplateList()
{
$url = 'https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=ACCESS_TOKEN';
return $this->callGetApi($url);
}
/**
* 删除帐号下的个人模板
* @param string $priTmplId 要删除的模板id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delTemplate($priTmplId)
{
$url = 'https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['priTmplId' => $priTmplId], true);
}
/**
* 发送订阅消息
* @param array $data 发送的消息对象数组
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function send(array $data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

105
WeMini/Ocr.php Normal file
View File

@ -0,0 +1,105 @@
<?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;
/**
* 小程序ORC服务
* Class Ocr
* @package WeMini
*/
class Ocr extends BasicWeChat
{
/**
* 本接口提供基于小程序的银行卡 OCR 识别
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function bankcard($data)
{
$url = 'https://api.weixin.qq.com/cv/ocr/bankcard?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, false);
}
/**
* 本接口提供基于小程序的营业执照 OCR 识别
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function businessLicense($data)
{
$url = 'https://api.weixin.qq.com/cv/ocr/bizlicense?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, false);
}
/**
* 本接口提供基于小程序的驾驶证 OCR 识别
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function driverLicense($data)
{
$url = 'https://api.weixin.qq.com/cv/ocr/drivinglicense?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, false);
}
/**
* 本接口提供基于小程序的身份证 OCR 识别
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function idcard($data)
{
$url = 'https://api.weixin.qq.com/cv/ocr/idcard?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, false);
}
/**
* 本接口提供基于小程序的通用印刷体 OCR 识别
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function printedText($data)
{
$url = 'https://api.weixin.qq.com/cv/ocr/comm?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, false);
}
/**
* 本接口提供基于小程序的行驶证 OCR 识别
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function vehicleLicense($data)
{
$url = 'https://api.weixin.qq.com/cv/ocr/driving?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, false);
}
}

41
WeMini/Operation.php Normal file
View File

@ -0,0 +1,41 @@
<?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 Operation
* @package WeMini
*/
class Operation extends BasicWeChat
{
/**
* 实时日志查询
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function realtimelogSearch($data)
{
$url = 'https://api.weixin.qq.com/wxaapi/userlog/userlog_search?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
@ -33,7 +35,6 @@ class Plugs extends BasicWeChat
public function apply($plugin_appid)
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => 'apply', 'plugin_appid' => $plugin_appid], true);
}
@ -46,7 +47,6 @@ class Plugs extends BasicWeChat
public function getList()
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => 'list'], true);
}
@ -60,10 +60,22 @@ class Plugs extends BasicWeChat
public function unbind($plugin_appid)
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => 'unbind', 'plugin_appid' => $plugin_appid], true);
}
/**
* 获取当前所有插件使用方
* 修改插件使用申请的状态
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function devplugin($data)
{
$url = 'https://api.weixin.qq.com/wxa/devplugin?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 4.获取当前所有插件使用方(供插件开发者调用)
@ -76,7 +88,6 @@ class Plugs extends BasicWeChat
public function devApplyList($page = 1, $num = 10)
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$data = ['action' => 'dev_apply_list', 'page' => $page, 'num' => $num];
return $this->callPostApi($url, $data, true);
}
@ -91,8 +102,6 @@ class Plugs extends BasicWeChat
public function devAgree($action = 'dev_agree')
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => $action], true);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
@ -36,7 +38,6 @@ class Poi extends BasicWeChat
public function addBearByPoi($related_name, $related_credential, $related_address, $related_proof_material)
{
$url = 'https://api.weixin.qq.com/wxa/addnearbypoi?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$data = [
'related_name' => $related_name, 'related_credential' => $related_credential,
'related_address' => $related_address, 'related_proof_material' => $related_proof_material,
@ -55,7 +56,6 @@ class Poi extends BasicWeChat
public function getNearByPoiList($page = 1, $page_rows = 1000)
{
$url = "https://api.weixin.qq.com/wxa/getnearbypoilist?page={$page}&page_rows={$page_rows}&access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callGetApi($url);
}
@ -69,7 +69,6 @@ class Poi extends BasicWeChat
public function delNearByPoiList($poi_id)
{
$url = "https://api.weixin.qq.com/wxa/delnearbypoi?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['poi_id' => $poi_id], true);
}
@ -84,8 +83,6 @@ class Poi extends BasicWeChat
public function setNearByPoiShowStatus($poi_id, $status)
{
$url = "https://api.weixin.qq.com/wxa/setnearbypoishowstatus?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['poi_id' => $poi_id, 'status' => $status], true);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
@ -18,35 +20,40 @@ use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
/**
* 微信小程序二维码管理
* 微信小程序二维码
* Class Qrcode
* @package WeMini
*/
class Qrcode extends BasicWeChat
{
/**
* 默认线条颜色
* @var string[]
*/
private $lineColor = ["r" => "0", "g" => "0", "b" => "0"];
/**
* 获取小程序码(永久有效)
* 接口A: 适用于需要的码数量较少的业务场景
* @param string $path 不能为空,最大长度 128 字节
* @param integer $width 二维码的宽度
* @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param array $line_color auto_color false 时生效
* @param null|string $outType 输出类型
* @return array|string
* @param bool $autoColor 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param null|array $lineColor auto_color false 时生效
* @param boolean $isHyaline 透明底色
* @param string|null $outType 输出类型
* @param array $extra 其他参数
* @return string|array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createMiniPath($path, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"], $outType = null)
public function createMiniPath($path, $width = 430, $autoColor = false, $lineColor = null, $isHyaline = true, $outType = null, array $extra = [])
{
$url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$data = ['path' => $path, 'width' => $width, 'auto_color' => $auto_color, 'line_color' => $line_color];
$result = Tools::post($url, Tools::arr2json($data));
if (json_decode($result)) {
return Tools::json2arr($result);
}
return is_null($outType) ? $result : $outType($result);
$lineColor = empty($lineColor) ? $this->lineColor : $lineColor;
$data = ['path' => $path, 'width' => $width, 'auto_color' => $autoColor, 'line_color' => $lineColor, 'is_hyaline' => $isHyaline];
return $this->parseResult(Tools::post($url, Tools::arr2json(array_merge($data, $extra))), $outType);
}
/**
@ -55,23 +62,23 @@ class Qrcode extends BasicWeChat
* @param string $scene 最大32个可见字符只支持数字
* @param string $page 必须是已经发布的小程序存在的页面
* @param integer $width 二维码的宽度
* @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param array $line_color auto_color false 时生效
* @param bool $autoColor 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param null|array $lineColor auto_color false 时生效
* @param bool $isHyaline 是否需要透明底色
* @param null|string $outType 输出类型
* @param array $extra 其他参数
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createMiniScene($scene, $page, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"], $outType = null)
public function createMiniScene($scene, $page = '', $width = 430, $autoColor = false, $lineColor = null, $isHyaline = true, $outType = null, array $extra = [])
{
$url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN';
$data = ['scene' => $scene, 'width' => $width, 'auto_color' => $auto_color, 'page' => $page, 'line_color' => $line_color];
$this->registerApi($url, __FUNCTION__, func_get_args());
$result = Tools::post($url, Tools::arr2json($data));
if (json_decode($result)) {
return Tools::json2arr($result);
}
return is_null($outType) ? $result : $outType($result);
$lineColor = empty($lineColor) ? $this->lineColor : $lineColor;
$data = ['scene' => $scene, 'width' => $width, 'page' => $page, 'auto_color' => $autoColor, 'line_color' => $lineColor, 'is_hyaline' => $isHyaline, 'check_path' => false];
if (empty($page)) unset($data['page']);
return $this->parseResult(Tools::post($url, Tools::arr2json(array_merge($data, $extra))), $outType);
}
/**
@ -79,7 +86,7 @@ class Qrcode extends BasicWeChat
* 接口C适用于需要的码数量较少的业务场景
* @param string $path 不能为空,最大长度 128 字节
* @param integer $width 二维码的宽度
* @param null|string $outType 输出类型
* @param string|null $outType 输出类型
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
@ -88,11 +95,26 @@ class Qrcode extends BasicWeChat
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$result = Tools::post($url, Tools::arr2json(['path' => $path, 'width' => $width]));
if (json_decode($result)) {
return Tools::json2arr($result);
}
return is_null($outType) ? $result : $outType($result);
return $this->parseResult(Tools::post($url, Tools::arr2json(['path' => $path, 'width' => $width])), $outType);
}
/**
* 解释接口数据
* @param bool|string $result
* @param null|string $outType
* @return array|mixed
* @throws \WeChat\Exceptions\InvalidResponseException
*/
private function parseResult($result, $outType)
{
if (is_array($json = json_decode($result, true))) {
if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) {
[$this->delAccessToken(), $this->isTry = true];
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
}
return Tools::json2arr($result);
} else {
return is_null($outType) ? $result : $outType($result);
}
}
}

80
WeMini/Scheme.php Normal file
View File

@ -0,0 +1,80 @@
<?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;
/**
* 小程序 URL-Scheme
* Class Scheme
* @package WeMini
*/
class Scheme extends BasicWeChat
{
/**
* 创建 URL-Scheme
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create($data)
{
$url = 'https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
/**
* 查询 URL-Scheme
* @param string $scheme
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query($scheme)
{
$url = 'https://api.weixin.qq.com/wxa/queryscheme?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['scheme' => $scheme], true);
}
/**
* 创建 URL-Link
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function urlLink($data)
{
$url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=ACCESS_TOKEN";
return $this->callPostApi($url, $data, true);
}
/**
* 查询 URL-Link
* @param string $urllink
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function urlQuery($urllink)
{
$url = 'https://api.weixin.qq.com/wxa/query_urllink?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['url_link' => $urllink], true);
}
}

40
WeMini/Search.php Normal file
View File

@ -0,0 +1,40 @@
<?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 Search
* @package WeMini
*/
class Search extends BasicWeChat
{
/**
* 提交小程序页面url及参数信息
* @param array $pages
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function submitPages($pages)
{
$url = 'https://api.weixin.qq.com/cgi-bin/guide/getguideacct?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['pages' => $pages], true);
}
}

68
WeMini/Security.php Normal file
View File

@ -0,0 +1,68 @@
<?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 Security
* @package WeMini
*/
class Security extends BasicWeChat
{
/**
* 校验一张图片是否含有违法违规内容
* @param string $media 要检测的图片文件格式支持PNG、JPEG、JPG、GIF图片尺寸不超过 750px x 1334px
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function imgSecCheck($media)
{
$url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['media' => $media], false, ['headers' => ['Content-Type: application/octet-stream']]);
}
/**
* 异步校验图片/音频是否含有违法违规内容
* @param string $media_url
* @param string $media_type
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function mediaCheckAsync($media_url, $media_type)
{
$url = 'https://api.weixin.qq.com/wxa/media_check_async?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['media_url' => $media_url, 'media_type' => $media_type], true);
}
/**
* 检查一段文本是否含有违法违规内容
* @param string $content
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function msgSecCheck($content)
{
$url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, ['content' => $content], true);
}
}

118
WeMini/Shipping.php Normal file
View File

@ -0,0 +1,118 @@
<?php
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 小程序发货信息管理服务
* @class Shipping
* @package WeMini
*/
class Shipping extends BasicWeChat
{
/**
* 发货信息录入接口
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function upload($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?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 combined($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/upload_combined_shipping_info?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 query($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/get_order?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 qlist($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/get_order_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 confirm($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/notify_confirm_receive?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 setJump($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/set_msg_jump_path?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 isTrade($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/is_trade_managed?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 isCompleted($data)
{
$url = 'https://api.weixin.qq.com/wxa/sec/order/is_trade_management_confirmation_completed?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

40
WeMini/Soter.php Normal file
View File

@ -0,0 +1,40 @@
<?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 Soter
* @package WeMini
*/
class Soter extends BasicWeChat
{
/**
* SOTER 生物认证秘钥签名验证
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function verifySignature($data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/soter/verify_signature?access_token=ACCESS_TOKEN';
return $this->callPostApi($url, $data, true);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
@ -33,7 +35,6 @@ class Template extends BasicWeChat
public function getTemplateLibraryList()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['offset' => '0', 'count' => '20'], true);
}
@ -47,7 +48,6 @@ class Template extends BasicWeChat
public function getTemplateLibrary($template_id)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['id' => $template_id], true);
}
@ -62,7 +62,6 @@ class Template extends BasicWeChat
public function addTemplate($template_id, array $keyword_id_list)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['id' => $template_id, 'keyword_id_list' => $keyword_id_list], true);
}
@ -75,7 +74,6 @@ class Template extends BasicWeChat
public function getTemplateList()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['offset' => '0', 'count' => '20'], true);
}
@ -89,7 +87,6 @@ class Template extends BasicWeChat
public function delTemplate($template_id)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['template_id' => $template_id], true);
}
@ -103,8 +100,6 @@ class Template extends BasicWeChat
public function send(array $data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
}

View File

@ -3,13 +3,15 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
@ -25,32 +27,30 @@ class Total extends BasicWeChat
{
/**
* 数据分析接口
* @param string $begin_date 开始日期
* @param string $end_date 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @param string $beginDate 开始日期
* @param string $endDate 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidDailySummarytrend($begin_date, $end_date)
public function getWeanalysisAppidDailySummarytrend($beginDate, $endDate)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
return $this->callPostApi($url, ['begin_date' => $beginDate, 'end_date' => $endDate], true);
}
/**
* 访问分析
* @param string $begin_date 开始日期
* @param string $end_date 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @param string $beginDate 开始日期
* @param string $endDate 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidDailyVisittrend($begin_date, $end_date)
public function getWeanalysisAppidDailyVisittrend($beginDate, $endDate)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
return $this->callPostApi($url, ['begin_date' => $beginDate, 'end_date' => $endDate], true);
}
/**
@ -64,7 +64,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidWeeklyVisittrend($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
@ -79,7 +78,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidMonthlyVisittrend($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
@ -94,7 +92,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidVisitdistribution($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
@ -109,7 +106,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidDailyRetaininfo($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
@ -124,7 +120,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidWeeklyRetaininfo($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
@ -139,7 +134,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidMonthlyRetaininfo($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyretaininfo?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
@ -154,7 +148,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidVisitPage($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
@ -169,8 +162,6 @@ class Total extends BasicWeChat
public function getWeanalysisAppidUserportrait($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
}

View File

@ -1,12 +1,10 @@
<?php
/**
* 对微信小程序用户加密数据的解密示例代码.
*
* 对微信小程序用户加密数据的解密示例代码
* Class WXBizDataCrypt
* @copyright Copyright (c) 1998-2014 Tencent Inc.
*/
class WXBizDataCrypt
{
private $appid;
@ -35,24 +33,25 @@ class WXBizDataCrypt
public function decryptData($encryptedData, $iv, &$data)
{
if (strlen($this->sessionKey) != 24) {
return \ErrorCode::$IllegalAesKey;
return ErrorCode::$IllegalAesKey;
}
$aesKey = base64_decode($this->sessionKey);
if (strlen($iv) != 24) {
return \ErrorCode::$IllegalIv;
return ErrorCode::$IllegalIv;
}
$aesIV = base64_decode($iv);
$aesCipher = base64_decode($encryptedData);
$result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
$dataObj = json_decode($result);
if ($dataObj == null) {
return \ErrorCode::$IllegalBuffer;
return ErrorCode::$IllegalBuffer;
}
if ($dataObj->watermark->appid != $this->appid) {
return \ErrorCode::$IllegalBuffer;
// 兼容新版本无 watermark 的情况
if (isset($dataObj->watermark) && $dataObj->watermark->appid != $this->appid) {
return ErrorCode::$IllegalBuffer;
}
$data = $result;
return \ErrorCode::$OK;
return ErrorCode::$OK;
}
}

View File

@ -3,18 +3,20 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicPay;
use WeChat\Contracts\BasicWePay;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidResponseException;
@ -23,7 +25,7 @@ use WeChat\Exceptions\InvalidResponseException;
* Class Bill
* @package WePay
*/
class Bill extends BasicPay
class Bill extends BasicWePay
{
/**
* 下载对账单
@ -31,6 +33,7 @@ class Bill extends BasicPay
* @param null|string $outType 输出类型
* @return bool|string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function download(array $options, $outType = null)
{
@ -38,7 +41,7 @@ class Bill extends BasicPay
$params = $this->params->merge($options);
$params['sign'] = $this->getPaySign($params, 'MD5');
$result = Tools::post('https://api.mch.weixin.qq.com/pay/downloadbill', Tools::arr2xml($params));
if (($jsonData = Tools::xml2arr($result))) {
if (is_array($jsonData = Tools::xml3arr($result))) {
if ($jsonData['return_code'] !== 'SUCCESS') {
throw new InvalidResponseException($jsonData['return_msg'], '0');
}
@ -52,6 +55,7 @@ class Bill extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function comment(array $options)
{

View File

@ -3,36 +3,39 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicPay;
use WeChat\Contracts\BasicWePay;
/**
* 微信商户代金券
* Class Coupon
* @package WePay
*/
class Coupon extends BasicPay
class Coupon extends BasicWePay
{
/**
* 发放代金券
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create(array $options)
{
$url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/send_coupon";
return $this->callPostApi($url, $options, true);
return $this->callPostApi($url, $options, true, 'MD5');
}
/**
@ -40,6 +43,7 @@ class Coupon extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryStock(array $options)
{
@ -52,6 +56,7 @@ class Coupon extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryInfo(array $options)
{

69
WePay/Custom.php Normal file
View File

@ -0,0 +1,69 @@
<?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 WePay;
use WeChat\Contracts\BasicWePay;
/**
* 微信扩展上报海关
* Class Custom
* @package WePay
*/
class Custom extends BasicWePay
{
/**
* 订单附加信息提交接口
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function add(array $options = [])
{
$url = 'https://api.mch.weixin.qq.com/cgi-bin/mch/customs/customdeclareorder';
return $this->callPostApi($url, $options, false, 'MD5', false, false);
}
/**
* 订单附加信息查询接口
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function get(array $options = [])
{
$url = 'https://api.mch.weixin.qq.com/cgi-bin/mch/customs/customdeclarequery';
return $this->callPostApi($url, $options, false, 'MD5', true, false);
}
/**
* 订单附加信息重推接口
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function reset(array $options = [])
{
$url = 'https://api.mch.weixin.qq.com/cgi-bin/mch/newcustoms/customdeclareredeclare';
return $this->callPostApi($url, $options, false, 'MD5', true, false);
}
}

View File

@ -3,18 +3,20 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicPay;
use WeChat\Contracts\BasicWePay;
use WeChat\Contracts\Tools;
/**
@ -22,7 +24,7 @@ use WeChat\Contracts\Tools;
* Class Order
* @package WePay
*/
class Order extends BasicPay
class Order extends BasicWePay
{
/**
@ -30,6 +32,7 @@ class Order extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create(array $options)
{
@ -37,11 +40,25 @@ class Order extends BasicPay
return $this->callPostApi($url, $options, false, 'MD5');
}
/**
* 刷卡支付
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function micropay(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/micropay';
return $this->callPostApi($url, $options, false, 'MD5');
}
/**
* 查询订单
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query(array $options)
{
@ -54,6 +71,7 @@ class Order extends BasicPay
* @param string $outTradeNo 商户订单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function close($outTradeNo)
{
@ -97,11 +115,31 @@ class Order extends BasicPay
return "weixin://wxpay/bizpayurl?" . http_build_query($data);
}
/**
* 获取微信App支付秘需参数
* @param string $prepayId 统一下单预支付码
* @return array
*/
public function appParams($prepayId)
{
$data = [
'appid' => $this->config->get('appid'),
'partnerid' => $this->config->get('mch_id'),
'prepayid' => (string)$prepayId,
'package' => 'Sign=WXPay',
'timestamp' => (string)time(),
'noncestr' => Tools::createNoncestr(),
];
$data['sign'] = $this->getPaySign($data, 'MD5');
return $data;
}
/**
* 刷卡支付 撤销订单
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function reverse(array $options)
{
@ -114,11 +152,12 @@ class Order extends BasicPay
* @param string $authCode 扫码支付授权码,设备读取用户微信中的条码或者二维码信息
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryAuthCode($authCode)
{
$url = 'https://api.mch.weixin.qq.com/tools/authcodetoopenid';
return $this->callPostApi($url, ['auth_code' => $authCode]);
return $this->callPostApi($url, ['auth_code' => $authCode], false, 'MD5', false);
}
/**
@ -126,6 +165,7 @@ class Order extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function report(array $options)
{

145
WePay/ProfitSharing.php Normal file
View File

@ -0,0 +1,145 @@
<?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 WePay;
use WeChat\Contracts\BasicWePay;
/**
* 微信分账
* Class ProfitSharing
* @package WePay
*/
class ProfitSharing extends BasicWePay
{
/**
* 请求单次分账
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharing(array $options)
{
$url = 'https://api.mch.weixin.qq.com/secapi/pay/profitsharing';
return $this->callPostApi($url, $options, true);
}
/**
* 请求多次分账
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function multiProfitSharing(array $options)
{
$url = 'https://api.mch.weixin.qq.com/secapi/pay/multiprofitsharing';
return $this->callPostApi($url, $options, true);
}
/**
* 查询分账结果
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharingQuery(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/profitsharingquery';
return $this->callPostApi($url, $options);
}
/**
* 添加分账接收方
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharingAddReceiver(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver';
return $this->callPostApi($url, $options);
}
/**
* 删除分账接收方
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharingRemoveReceiver(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/profitsharingremovereceiver';
return $this->callPostApi($url, $options);
}
/**
* 完结分账
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharingFinish(array $options)
{
$url = 'https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish';
return $this->callPostApi($url, $options, true);
}
/**
* 查询订单待分账金额
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharingOrderAmountQuery(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/profitsharingorderamountquery';
return $this->callPostApi($url, $options);
}
/**
* 分账回退
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharingReturn(array $options)
{
$url = 'https://api.mch.weixin.qq.com/secapi/pay/profitsharingreturn';
return $this->callPostApi($url, $options, true);
}
/**
* 回退结果查询
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function profitSharingReturnQuery(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/profitsharingreturnquery';
return $this->callPostApi($url, $options);
}
}

View File

@ -3,25 +3,27 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicPay;
use WeChat\Contracts\BasicWePay;
/**
* 微信红包支持
* Class Redpack
* @package WePay
*/
class Redpack extends BasicPay
class Redpack extends BasicWePay
{
/**
@ -29,6 +31,7 @@ class Redpack extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create(array $options)
{
@ -43,6 +46,7 @@ class Redpack extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function groups(array $options)
{
@ -57,6 +61,7 @@ class Redpack extends BasicPay
* @param string $mchBillno 商户发放红包的商户订单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query($mchBillno)
{

View File

@ -3,19 +3,22 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicPay;
use WeChat\Contracts\BasicWePay;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidDecryptException;
use WeChat\Exceptions\InvalidResponseException;
/**
@ -23,7 +26,7 @@ use WeChat\Exceptions\InvalidResponseException;
* Class Refund
* @package WePay
*/
class Refund extends BasicPay
class Refund extends BasicWePay
{
/**
@ -31,6 +34,7 @@ class Refund extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create(array $options)
{
@ -43,6 +47,7 @@ class Refund extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query(array $options)
{
@ -52,25 +57,25 @@ class Refund extends BasicPay
/**
* 获取退款通知
* @param string|array $xml
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function getNotify()
public function getNotify($xml = '')
{
$data = Tools::xml2arr(file_get_contents("php://input"));
$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失败');
}
if (!class_exists('Prpcrypt', false)) {
include dirname(__DIR__) . '/WeChat/Contracts/Prpcrypt.php';
try {
$key = md5($this->config->get('mch_key'));
$decrypt = base64_decode($data['req_info']);
$response = openssl_decrypt($decrypt, 'aes-256-ecb', $key, OPENSSL_RAW_DATA);
$data['result'] = Tools::xml2arr($response);
return $data;
} catch (\Exception $exception) {
throw new InvalidDecryptException($exception->getMessage(), $exception->getCode());
}
$pc = new \Prpcrypt(md5($this->config->get('mch_key')));
$array = $pc->decrypt(base64_decode($data['req_info']));
if (intval($array[0]) > 0) {
throw new InvalidResponseException($array[1], $array[0]);
}
$data['decode'] = $array[1];
return $data;
}
}

View File

@ -3,25 +3,27 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicPay;
use WeChat\Contracts\BasicWePay;
/**
* 微信商户打款到零钱
* Class Transfers
* @package WePay
*/
class Transfers extends BasicPay
class Transfers extends BasicWePay
{
/**
@ -29,6 +31,7 @@ class Transfers extends BasicPay
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create(array $options)
{
@ -45,6 +48,7 @@ class Transfers extends BasicPay
* @param string $partnerTradeNo 商户调用企业付款API时使用的商户订单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query($partnerTradeNo)
{

View File

@ -3,18 +3,20 @@
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// | 版权所有 2014~2024 ThinkAdmin [ thinkadmin.top ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// | gitee 代码仓库https://gitee.com/zoujingli/WeChatDeveloper
// | github 代码仓库https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicPay;
use WeChat\Contracts\BasicWePay;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidArgumentException;
use WeChat\Exceptions\InvalidDecryptException;
@ -25,7 +27,7 @@ use WeChat\Exceptions\InvalidResponseException;
* Class TransfersBank
* @package WePay
*/
class TransfersBank extends BasicPay
class TransfersBank extends BasicWePay
{
/**
@ -68,7 +70,7 @@ class TransfersBank extends BasicPay
* 商户企业付款到银行卡操作进行结果查询
* @param string $partnerTradeNo 商户订单号,需保持唯一
* @return array
* @throws InvalidResponseException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query($partnerTradeNo)
@ -121,5 +123,4 @@ class TransfersBank extends BasicPay
Tools::setCache($cacheKey, $data['pub_key'], 600);
return $data['pub_key'];
}
}

63
WePayV3/Cert.php Normal file
View File

@ -0,0 +1,63 @@
<?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;
use WePayV3\Contracts\DecryptAes;
/**
* 平台证书管理
* Class Cert
* @package WePayV3
*/
class Cert extends BasicWePay
{
/**
* 自动配置平台证书
* @var bool
*/
protected $autoCert = false;
/**
* 商户平台下载证书
* @return void
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function download()
{
try {
$aes = new DecryptAes($this->config['mch_v3_key']);
$result = $this->doRequest('GET', '/v3/certificates');
$certs = [];
foreach ($result['data'] as $vo) {
$certs[$vo['serial_no']] = [
'expire' => strtotime($vo['expire_time']),
'content' => $aes->decryptToString(
$vo['encrypt_certificate']['associated_data'],
$vo['encrypt_certificate']['nonce'],
$vo['encrypt_certificate']['ciphertext']
)
];
}
$this->tmpFile("{$this->config['mch_id']}_certs", $certs);
} catch (\Exception $exception) {
throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
}
}
}

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

@ -0,0 +1,429 @@
<?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\Contracts;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidArgumentException;
use WeChat\Exceptions\InvalidDecryptException;
use WeChat\Exceptions\InvalidResponseException;
use WePayV3\Cert;
/**
* 微信支付基础类
* Class BasicWePay
* @package WePayV3
*/
abstract class BasicWePay
{
/**
* 接口基础地址
* @var string
*/
protected $base = 'https://api.mch.weixin.qq.com';
/**
* 实例对象静态缓存
* @var array
*/
static $cache = [];
/**
* 自动配置平台证书
* @var bool
*/
protected $autoCert = true;
/**
* 配置参数
* @var array
*/
protected $config = [
'appid' => '', // 微信绑定APPID需配置
'mch_id' => '', // 微信商户编号,需要配置
'mch_v3_key' => '', // 微信商户密钥,需要配置
'cert_serial' => '', // 商户证书序号,无需配置
'cert_public' => '', // 商户公钥内容,需要配置
'cert_private' => '', // 商户密钥内容,需要配置
'mp_cert_serial' => '', // 平台证书序号,无需配置
'mp_cert_content' => '', // 平台证书内容,无需配置
];
/**
* BasicWePayV3 constructor.
* @param array $options [mch_id, mch_v3_key, cert_public, cert_private]
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function __construct(array $options = [])
{
if (empty($options['mch_id'])) {
throw new InvalidArgumentException("Missing Config -- [mch_id]");
}
if (empty($options['mch_v3_key'])) {
throw new InvalidArgumentException("Missing Config -- [mch_v3_key]");
}
if (empty($options['cert_public'])) {
throw new InvalidArgumentException("Missing Config -- [cert_public]");
}
if (empty($options['cert_private'])) {
throw new InvalidArgumentException("Missing Config -- [cert_private]");
}
if (stripos($options['cert_public'], '-----BEGIN CERTIFICATE-----') === false) {
if (file_exists($options['cert_public'])) {
$options['cert_public'] = file_get_contents($options['cert_public']);
} else {
throw new InvalidArgumentException("File Non-Existent -- [cert_public]");
}
}
if (stripos($options['cert_private'], '-----BEGIN PRIVATE KEY-----') === false) {
if (file_exists($options['cert_private'])) {
$options['cert_private'] = file_get_contents($options['cert_private']);
} else {
throw new InvalidArgumentException("File Non-Existent -- [cert_private]");
}
}
$this->config['appid'] = isset($options['appid']) ? $options['appid'] : '';
$this->config['mch_id'] = $options['mch_id'];
$this->config['mch_v3_key'] = $options['mch_v3_key'];
$this->config['cert_public'] = $options['cert_public'];
$this->config['cert_private'] = $options['cert_private'];
if (empty($options['cert_serial'])) {
$this->config['cert_serial'] = openssl_x509_parse($this->config['cert_public'], true)['serialNumberHex'];
} else {
$this->config['cert_serial'] = $options['cert_serial'];
}
if (empty($this->config['cert_serial'])) {
throw new InvalidArgumentException('Failed to parse certificate public key');
}
if (!empty($options['cache_path'])) {
Tools::$cache_path = $options['cache_path'];
}
// 自动配置平台证书
if ($this->autoCert) {
$this->_autoCert();
}
// 服务商参数支持
// if (!empty($options['sp_appid'])) {
// $this->config['sp_appid'] = $options['sp_appid'];
// }
// if (!empty($options['sp_mchid'])) {
// $this->config['sp_mchid'] = $options['sp_mchid'];
// }
// if (!empty($options['sub_appid'])) {
// $this->config['sub_appid'] = $options['sub_appid'];
// }
// if (!empty($options['sub_mch_id'])) {
// $this->config['sub_mch_id'] = $options['sub_mch_id'];
// }
}
/**
* 静态创建对象
* @param array $config
* @return static
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public static function instance($config)
{
$key = md5(get_called_class() . serialize($config));
if (isset(self::$cache[$key])) return self::$cache[$key];
return self::$cache[$key] = new static($config);
}
/**
* 模拟发起请求
* @param string $method 请求访问
* @param string $pathinfo 请求路由
* @param string $jsondata 请求数据
* @param boolean $verify 是否验证
* @param boolean $isjson 返回JSON
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function doRequest($method, $pathinfo, $jsondata = '', $verify = false, $isjson = true)
{
list($time, $nonce) = [time(), uniqid() . rand(1000, 9999)];
$signstr = join("\n", [$method, $pathinfo, $time, $nonce, $jsondata, '']);
// 生成数据签名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'], $this->signBuild($signstr)
);
$location = (preg_match('|^https?://|', $pathinfo) ? '' : $this->base) . $pathinfo;
list($header, $content) = $this->_doRequestCurl($method, $location, [
'data' => $jsondata, 'header' => [
'Accept: application/json',
'Content-Type: application/json',
'User-Agent: https://thinkadmin.top',
"Authorization: WECHATPAY2-SHA256-RSA2048 {$token}",
"Wechatpay-Serial: {$this->config['mp_cert_serial']}"
],
]);
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;
}
/**
* 模拟发起上传请求
* @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 请求方法
* @param string $location 请求方法
* @param array $options 请求参数 [data, header]
* @return array [header,content]
*/
private function _doRequestCurl($method, $location, $options = [])
{
$curl = curl_init();
// POST数据设置
if (strtolower($method) === 'post') {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $options['data']);
}
// CURL头信息设置
if (!empty($options['header'])) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $options['header']);
}
curl_setopt($curl, CURLOPT_URL, $location);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$content = curl_exec($curl);
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
curl_close($curl);
return [substr($content, 0, $headerSize), substr($content, $headerSize)];
}
/**
* 生成数据签名
* @param string $data 签名内容
* @return string
*/
protected function signBuild($data)
{
$pkeyid = openssl_pkey_get_private($this->config['cert_private']);
openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption');
return base64_encode($signature);
}
/**
* 验证内容签名
* @param string $data 签名内容
* @param string $sign 原签名值
* @param string $serial 证书序号
* @return int
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function signVerify($data, $sign, $serial)
{
$cert = $this->_getCert($serial);
return @openssl_verify($data, base64_decode($sign), openssl_x509_read($cert), 'sha256WithRSAEncryption');
}
/**
* 获取平台证书
* @param string $serial
* @return string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function _getCert($serial = '')
{
$certs = $this->tmpFile("{$this->config['mch_id']}_certs");
if (empty($certs) || empty($certs[$serial]['content'])) {
Cert::instance($this->config)->download();
$certs = $this->tmpFile("{$this->config['mch_id']}_certs");
}
if (empty($certs[$serial]['content']) || $certs[$serial]['expire'] < time()) {
throw new InvalidResponseException("读取平台证书失败!");
} else {
return $certs[$serial]['content'];
}
}
/**
* 自动配置平台证书
* @return void
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function _autoCert()
{
$certs = $this->tmpFile("{$this->config['mch_id']}_certs");
if (is_array($certs)) foreach ($certs as $k => $v) {
if ($v['expire'] < time()) unset($certs[$k]);
}
if (empty($certs)) {
Cert::instance($this->config)->download();
$certs = $this->tmpFile("{$this->config['mch_id']}_certs");
}
if (empty($certs) || !is_array($certs)) {
throw new InvalidResponseException("读取平台证书失败!");
}
foreach ($certs as $k => $v) if ($v['expire'] > time() + 10) {
$this->config['mp_cert_serial'] = $k;
$this->config['mp_cert_content'] = $v['content'];
break;
}
if (empty($this->config['mp_cert_serial']) || empty($this->config['mp_cert_content'])) {
throw new InvalidResponseException("自动配置平台证书失败!");
}
}
/**
* 写入或读取临时文件
* @param string $name
* @param null|array|string $content
* @param integer $expire
* @return array|string
* @throws \WeChat\Exceptions\LocalCacheException
*/
protected function tmpFile($name, $content = null, $expire = 7200)
{
if (is_null($content)) {
$text = Tools::getCache($name);
if (empty($text)) return '';
$json = json_decode(Tools::getCache($name) ?: '', true);
return isset($json[0]) ? $json[0] : '';
} else {
return Tools::setCache($name, json_encode([$content], JSON_UNESCAPED_UNICODE), $expire);
}
}
/**
* RSA加密处理-平台证书
* @param string $string
* @return string
* @throws \WeChat\Exceptions\InvalidDecryptException
*/
protected function rsaEncode($string)
{
$publicKey = $this->config['mp_cert_content'];
if (openssl_public_encrypt($string, $encrypted, $publicKey, OPENSSL_PKCS1_OAEP_PADDING)) {
return base64_encode($encrypted);
} else {
throw new InvalidDecryptException('Rsa Encrypt Error.');
}
}
}

View File

@ -0,0 +1,83 @@
<?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\Contracts;
use WeChat\Exceptions\InvalidArgumentException;
use WeChat\Exceptions\InvalidDecryptException;
/**
* Aes 解密工具类
* Class DecryptAes
* @package WePayV3\Contracts
*/
class DecryptAes
{
private $aesKey;
const KEY_LENGTH_BYTE = 32;
const AUTH_TAG_LENGTH_BYTE = 16;
/**
* Constructor
* @param string $aesKey
*/
public function __construct($aesKey)
{
if (strlen($aesKey) != self::KEY_LENGTH_BYTE) {
throw new InvalidArgumentException('无效的ApiV3Key长度应为32个字节');
}
$this->aesKey = $aesKey;
}
/**
* Decrypt AEAD_AES_256_GCM ciphertext
* @param string $associatedData AES GCM additional authentication data
* @param string $nonceStr AES GCM nonce
* @param string $ciphertext AES GCM cipher text
* @return string|bool Decrypted string on success or FALSE on failure
* @throws \WeChat\Exceptions\InvalidDecryptException
*/
public function decryptToString($associatedData, $nonceStr, $ciphertext)
{
$ciphertext = \base64_decode($ciphertext);
if (strlen($ciphertext) <= self::AUTH_TAG_LENGTH_BYTE) {
return false;
}
try {
// ext-sodium (default installed on >= PHP 7.2)
if (function_exists('\sodium_crypto_aead_aes256gcm_is_available') && \sodium_crypto_aead_aes256gcm_is_available()) {
return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $this->aesKey);
}
// ext-libsodium (need install libsodium-php 1.x via pecl)
if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && \Sodium\crypto_aead_aes256gcm_is_available()) {
return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $this->aesKey);
}
// openssl (PHP >= 7.1 support AEAD)
if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) {
$ctext = substr($ciphertext, 0, -self::AUTH_TAG_LENGTH_BYTE);
$authTag = substr($ciphertext, -self::AUTH_TAG_LENGTH_BYTE);
return \openssl_decrypt($ctext, 'aes-256-gcm', $this->aesKey, \OPENSSL_RAW_DATA, $nonceStr, $authTag, $associatedData);
}
} catch (\Exception $exception) {
throw new InvalidDecryptException($exception->getMessage(), $exception->getCode());
} catch (\SodiumException $exception) {
throw new InvalidDecryptException($exception->getMessage(), $exception->getCode());
}
throw new InvalidDecryptException('AEAD_AES_256_GCM 需要 PHP 7.1 以上或者安装 libsodium-php');
}
}

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 [];
}
}
}

202
WePayV3/Order.php Normal file
View File

@ -0,0 +1,202 @@
<?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 WeChat\Exceptions\InvalidArgumentException;
use WeChat\Exceptions\InvalidResponseException;
use WePayV3\Contracts\BasicWePay;
use WePayV3\Contracts\DecryptAes;
/**
* 直连商户 | 订单支付接口
* Class Order
* @package WePayV3
*/
class Order extends BasicWePay
{
const WXPAY_H5 = 'h5';
const WXPAY_APP = 'app';
const WXPAY_JSAPI = 'jsapi';
const WXPAY_NATIVE = 'native';
/**
* 创建支付订单
* @param string $type 支付类型
* @param array $data 支付参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
*/
public function create($type, $data)
{
$types = [
'h5' => '/v3/pay/transactions/h5',
'app' => '/v3/pay/transactions/app',
'jsapi' => '/v3/pay/transactions/jsapi',
'native' => '/v3/pay/transactions/native',
];
if (empty($types[$type])) {
throw new InvalidArgumentException("Payment {$type} not defined.");
} else {
// 创建预支付码
$result = $this->doRequest('POST', $types[$type], json_encode($data, JSON_UNESCAPED_UNICODE), true);
if (empty($result['h5_url']) && empty($result['code_url']) && empty($result['prepay_id'])) {
$message = isset($result['code']) ? "[ {$result['code']} ] " : '';
$message .= isset($result['message']) ? $result['message'] : json_encode($result, JSON_UNESCAPED_UNICODE);
throw new InvalidResponseException($message);
}
// 支付参数签名
$time = strval(time());
$appid = $this->config['appid'];
$nonceStr = Tools::createNoncestr();
if ($type === 'app') {
$sign = $this->signBuild(join("\n", [$appid, $time, $nonceStr, $result['prepay_id'], '']));
return ['partnerId' => $this->config['mch_id'], 'prepayId' => $result['prepay_id'], 'package' => 'Sign=WXPay', 'nonceStr' => $nonceStr, 'timeStamp' => $time, 'sign' => $sign];
} elseif ($type === 'jsapi') {
$sign = $this->signBuild(join("\n", [$appid, $time, $nonceStr, "prepay_id={$result['prepay_id']}", '']));
return ['appId' => $appid, 'timestamp' => $time, 'timeStamp' => $time, 'nonceStr' => $nonceStr, 'package' => "prepay_id={$result['prepay_id']}", 'signType' => 'RSA', 'paySign' => $sign];
} else {
return $result;
}
}
}
/**
* 支付订单查询
* @param string $tradeNo 订单单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml
*/
public function query($tradeNo)
{
$pathinfo = "/v3/pay/transactions/out-trade-no/{$tradeNo}";
return $this->doRequest('GET', "{$pathinfo}?mchid={$this->config['mch_id']}", '', true);
}
/**
* 关闭支付订单
* @param string $tradeNo 订单单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function close($tradeNo)
{
$data = ['mchid' => $this->config['mch_id']];
$path = "/v3/pay/transactions/out-trade-no/{$tradeNo}/close";
return $this->doRequest('POST', $path, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 支付通知解析
* @param array $data
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
*/
public function notify(array $data = [])
{
if (empty($data)) {
$data = json_decode(Tools::getRawInput(), true);
}
if (isset($data['resource'])) {
$aes = new DecryptAes($this->config['mch_v3_key']);
$data['result'] = $aes->decryptToString(
$data['resource']['associated_data'],
$data['resource']['nonce'],
$data['resource']['ciphertext']
);
}
return $data;
}
/**
* 创建退款订单
* @param array $data 退款参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
*/
public function createRefund($data)
{
$path = '/v3/refund/domestic/refunds';
return $this->doRequest('POST', $path, json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 退款订单查询
* @param string $refundNo 退款单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml
*/
public function queryRefund($refundNo)
{
$path = "/v3/refund/domestic/refunds/{$refundNo}";
return $this->doRequest('GET', $path, '', true);
}
/**
* 获取退款通知
* @param mixed $data
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
* @deprecated 直接使用 Notify 方法
*/
public function notifyRefund($data = [])
{
return $this->notify($data);
}
/**
* 申请交易账单
* @param array|string $params
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_6.shtml
*/
public function tradeBill($params)
{
$path = '/v3/bill/tradebill?' . is_array($params) ? http_build_query($params) : $params;
return $this->doRequest('GET', $path, '', true);
}
/**
* 申请资金账单
* @param array|string $params
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_7.shtml
*/
public function fundflowBill($params)
{
$path = '/v3/bill/fundflowbill?' . is_array($params) ? http_build_query($params) : $params;
return $this->doRequest('GET', $path, '', true);
}
/**
* 下载账单文件
* @param string $fileurl
* @return string 二进制 Excel 内容
* @throws \WeChat\Exceptions\InvalidResponseException
* @document https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_1.shtml
*/
public function downloadBill($fileurl)
{
return $this->doRequest('GET', $fileurl, '', false, false);
}
}

115
WePayV3/ProfitSharing.php Normal file
View File

@ -0,0 +1,115 @@
<?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 WePayV3\Contracts\BasicWePay;
/**
* 普通商户商家分账
* Class Profitsharing
* @package WePayV3
*/
class ProfitSharing extends BasicWePay
{
/**
* 请求分账
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
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 商户分账单号
* @param string $transactionId 微信订单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function query($outOrderNo, $transactionId)
{
$pathinfo = "/v3/profitsharing/orders/{$outOrderNo}?&transaction_id={$transactionId}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 解冻剩余资金
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function unfreeze(array $options)
{
return $this->doRequest('POST', '/v3/profitsharing/orders/unfreeze', json_encode($options, JSON_UNESCAPED_UNICODE), true);
}
/**
* 查询剩余待分金额
* @param string $transactionId 微信订单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function amounts($transactionId)
{
$pathinfo = "/v3/profitsharing/transactions/{$transactionId}/amounts";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 添加分账接收方
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
*/
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);
}
/**
* 删除分账接收方
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
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);
}
}

82
WePayV3/Refund.php Normal file
View File

@ -0,0 +1,82 @@
<?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 WePayV3\Contracts\BasicWePay;
/**
* 订单退款接口
* 注意:直连商户退款接口集成在 Order
* @deprecated
* @class Refund
* @package WePayV3
*/
class Refund extends BasicWePay
{
/**
* 创建退款订单
* @param array $data 退款参数
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create($data)
{
return Order::instance($this->config)->createRefund($data);
// return $this->doRequest('POST', '/v3/ecommerce/refunds/apply', json_encode($data, JSON_UNESCAPED_UNICODE), true);
}
/**
* 退款订单查询
* @param string $refundNo 退款单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query($refundNo)
{
return Order::instance($this->config)->queryRefund($refundNo);
// $pathinfo = "/v3/ecommerce/refunds/out-refund-no/{$refundNo}";
// return $this->doRequest('GET', "{$pathinfo}?sub_mchid={$this->config['mch_id']}", '', true);
}
/**
* 获取退款通知
* @param mixed $xml
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function notify($xml = [])
{
return Order::instance($this->config)->notify($xml);
// $data = Tools::xml2arr(empty($xml) ? Tools::getRawInput() : $xml);
// if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS') {
// throw new InvalidResponseException('获取退款通知XML失败');
// }
// try {
// $key = md5($this->config['mch_v3_key']);
// $decrypt = base64_decode($data['req_info']);
// $response = openssl_decrypt($decrypt, 'aes-256-ecb', $key, OPENSSL_RAW_DATA);
// $data['result'] = Tools::xml2arr($response);
// return $data;
// } catch (\Exception $exception) {
// throw new InvalidDecryptException($exception->getMessage(), $exception->getCode());
// }
}
}

107
WePayV3/Transfers.php Normal file
View File

@ -0,0 +1,107 @@
<?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 WePayV3\Contracts\BasicWePay;
/**
* 普通商户商家转账到零钱
* @class Transfers
* @package WePayV3
*/
class Transfers extends BasicWePay
{
/**
* 发起商家批量转账
* @param array $body
* @return array
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
* @link https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_1.shtml
*/
public function batchs($body)
{
if (empty($body['appid'])) {
$body['appid'] = $this->config['appid'];
}
if (isset($body['transfer_detail_list']) && is_array($body['transfer_detail_list'])) {
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'));
}
}
return $this->doRequest('POST', '/v3/transfer/batches', json_encode($body, JSON_UNESCAPED_UNICODE), true);
}
/**
* 通过微信批次单号查询批次单
* @param string $batchId 微信批次单号(二选一)
* @param string $outBatchNo 商家批次单号(二选一)
* @param boolean $needQueryDetail 查询指定状态
* @param integer $offset 请求资源的起始位置
* @param integer $limit 最大明细条数
* @param string $detailStatus 查询指定状态
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function query($batchId = '', $outBatchNo = '', $needQueryDetail = true, $offset = 0, $limit = 20, $detailStatus = 'ALL')
{
if (empty($batchId)) {
$pathinfo = "/v3/transfer/batches/out-batch-no/{$outBatchNo}";
} else {
$pathinfo = "/v3/transfer/batches/batch-id/{$batchId}";
}
$params = http_build_query([
'limit' => $limit,
'offset' => $offset,
'detail_status' => $detailStatus,
'need_query_detail' => $needQueryDetail ? 'true' : 'false',
]);
return $this->doRequest('GET', "{$pathinfo}?{$params}", '', true);
}
/**
* 通过微信明细单号查询明细单
* @param string $batchId 微信批次单号
* @param string $detailId 微信支付系统内部区分转账批次单下不同转账明细单的唯一标识
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function detailBatchId($batchId, $detailId)
{
$pathinfo = "/v3/transfer/batches/batch-id/{$batchId}/details/detail-id/{$detailId}";
return $this->doRequest('GET', $pathinfo, '', true);
}
/**
* 通过商家明细单号查询明细单
* @param string $outBatchNo 商户系统内部的商家批次单号,在商户系统内部唯一
* @param string $outDetailNo 商户系统内部区分转账批次单下不同转账明细单的唯一标识
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
public function detailOutBatchNo($outBatchNo, $outDetailNo)
{
$pathinfo = "/v3/transfer/batches/out-batch-no/{$outBatchNo}/details/out-detail-no/{$outDetailNo}";
return $this->doRequest('GET', $pathinfo, '', true);
}
}

46
_test/alipay-app.php Normal file
View File

@ -0,0 +1,46 @@
<?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
// +----------------------------------------------------------------------
// 1. 手动加载入口文件
include "../include.php";
// 2. 准备公众号配置参数
$config = include "./alipay.php";
try {
// 实例支付对象
// $pay = \We::AliPayApp($config);
// $pay = new \AliPay\App($config);
$pay = \AliPay\App::instance($config);
// 请参考请求参数https://docs.open.alipay.com/api_1/alipay.trade.app.pay
$result = $pay->apply([
'out_trade_no' => strval(time()), // 商户订单号
'total_amount' => '1', // 支付金额
'subject' => '支付宝订单标题', // 支付订单描述
]);
echo $result . PHP_EOL .'<br></br>'. PHP_EOL;
// 请求关闭订单
$result = $pay->close([
'out_trade_no' => strval(time())
]);
echo PHP_EOL . PHP_EOL . $result;
} catch (\Exception $e) {
echo $e->getMessage();
}

47
_test/alipay-bill.php Normal file
View File

@ -0,0 +1,47 @@
<?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
// +----------------------------------------------------------------------
// 1. 手动加载入口文件
include "../include.php";
// 2. 准备公众号配置参数
$config = include "./alipay.php";
try {
// 实例支付对象
// $pay = new \AliPay\Bill($config);
// $pay = \We::AliPayBill($config);
$pay = \AliPay\Bill::instance($config);
/**
* 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型,支持:
* trade商户基于支付宝交易收单的业务账单
* signcustomer基于商户支付宝余额收入及支出等资金变动的账务账单
* merchant_act营销活动账单包含营销活动的发放核销记录
* trade_zft_merchant直付通二级商户查询交易的业务账单
* zft_acc直付通平台商查询二级商户流水使用返回所有二级商户流水。
*/
// 请参考请求参数https://docs.open.alipay.com/api_15/alipay.data.dataservice.bill.downloadurl.query
$result = $pay->apply([
'bill_date' => date('Y-m-d', strtotime('-1 month')), // 账单时间(日账单yyyy-MM-dd,月账单 yyyy-MM)
'bill_type' => 'trade',
]);
echo '<pre>';
var_export($result);
} catch (Exception $e) {
echo $e->getMessage();
}

41
_test/alipay-notify.php Normal file
View File

@ -0,0 +1,41 @@
<?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
// +----------------------------------------------------------------------
// 1. 手动加载入口文件
include "../include.php";
// 2. 准备公众号配置参数
$config = include "./alipay.php";
try {
// 实例支付对象
// $pay = \We::AliPayApp($config);
// $pay = new \AliPay\App($config);
$pay = \AliPay\App::instance($config);
$data = $pay->notify();
if (in_array($data['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) {
// @todo 更新订单状态,支付完成
file_put_contents('notify.txt', "收到来自支付宝的异步通知\r\n", FILE_APPEND);
file_put_contents('notify.txt', '订单号:' . $data['out_trade_no'] . "\r\n", FILE_APPEND);
file_put_contents('notify.txt', '订单金额:' . $data['total_amount'] . "\r\n\r\n", FILE_APPEND);
} else {
file_put_contents('notify.txt', "收到异步通知\r\n", FILE_APPEND);
}
} catch (\Exception $e) {
// 异常处理
echo $e->getMessage();
}

43
_test/alipay-pos.php Normal file
View File

@ -0,0 +1,43 @@
<?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
// +----------------------------------------------------------------------
// 1. 手动加载入口文件
include "../include.php";
// 2. 准备公众号配置参数
$config = include "./alipay.php";
try {
// 实例支付对象
// $pay = We::AliPayPos($config);
// $pay = new \AliPay\Pos($config);
$pay = \AliPay\Pos::instance($config);
// 参数链接https://docs.open.alipay.com/api_1/alipay.trade.pay
$result = $pay->apply([
'out_trade_no' => '4312412343', // 订单号
'total_amount' => '13', // 订单金额,单位:元
'subject' => '订单商品标题', // 订单商品标题
'auth_code' => '123456', // 授权码
]);
echo '<pre>';
var_export($result);
} catch (Exception $e) {
echo $e->getMessage();
}

Some files were not shown because too many files have changed in this diff Show More