PHP development technology exchange (QQ group 513350915)
WeChatDeveloper is based on the official interface package. Before doing WeChat development, you must first read the WeChat official documentation.
There is also a help material prepared for WeChatDeveloper for reference.
WeChatDeveloper is an open source project, allowing it to be used anywhere without any restrictions. Forks of the project are welcome.
Our code repository has been moved to Github , while Gitee and Gitcode are only used as domestic mirror repositories to facilitate the majority of developers to obtain and use them. If you want to submit a PR or ISSUE, please operate it in the WeChatDeveloper warehouse. If you operate or submit an issue in other warehouses, it will not be processed!
file name | Class name | describe | type | Load ① |
---|---|---|---|---|
App.php | AliPayApp | Alipay App payment | Alipay payment | We::AliPayApp() |
Bill.php | AliPayBill | Alipay bill download | Alipay payment | We::AliPayBill() |
Pos.php | AliPayPos | Alipay card payment | Alipay payment | We::AliPayPos() |
Scan.php | AliPayScan | Alipay scan code payment | Alipay payment | We::AliPayScan() |
Transfer.php | AliPayTransfer | Alipay transfer | Alipay payment | We::AliPayTransfer() |
Wap.php | AliPayWap | Alipay Wap payment | Alipay payment | We::AliPayWap() |
Web.php | AliPayWeb | Alipay Web payment | Alipay payment | We::AliPayWeb() |
Card.php | WeChatCard | WeChat card and coupon interface support | Certification service number | We::WeChatCard() |
Custom.php | WeChatCustom | WeChat customer service message interface support | Certification service number | We::WeChatCustom() |
Media.php | WeChatMedia | WeChat media material interface support | Certification service number | We::WeChatMedia() |
Oauth.php | WeChatOauth | WeChat web page authorization message interface | Authentication service number | We::WeChatOauth() |
Pay.php | WeChatPay | WeChat payment interface | Certification service number | We::WeChatPay() |
Product.php | WeChatProduct | WeChat store interface | Certification service number | We::WeChatProduct() |
Qrcode.php | WeChatQrcode | WeChat QR code interface support | Certification service number | We::WeChatQrcode() |
Receive.php | WeChatReceive | WeChat push event message processing support | Certification service number | We::WeChatReceive() |
Scan.php | WeChatScan | WeChat scan interface support | Certification service number | We::WeChatScan() |
Script.php | WeChatScript | WeChat front-end JSSDK support | Certification service number | We::WeChatScript() |
Shake.php | WeChatShake | WeChat Bluetooth device push interface | Certification service number | We::WeChatShake() |
Tags.php | WeChatTags | WeChat fan tag interface support | Certification service number | We::WeChatTags() |
Template.php | WeChatTemplate | WeChat template message interface support | Certification service number | We::WeChatTemplate() |
User.php | WeChatUser | WeChat fan management interface support | Certification service number | We::WeChatCard() |
Wifi.php | WeChatWifi | WeChat store WIFI management support | Certification service number | We::WeChatWifi() |
Draft.php | WeChatDraft | WeChat draft box | Certification service number | We::WeChatDraft() |
Freepublish.php | WeChatFreepublish | WeChat publishing capability | Certification service number | We::WeChatFreepublish() |
Bill.php | WePayBill | WeChat merchant bills and comments | WeChat Pay | We::WePayBill() |
Coupon.php | WePayCoupon | WeChat merchant vouchers | WeChat Pay | We::WePayCoupon() |
Order.php | WePayOrder | WeChat merchant orders | WeChat Pay | We::WePayOrder() |
Redpack.php | WePayRedpack | WeChat red envelope support | WeChat Pay | We::WePayRedpack() |
Refund.php | WePayRefund | WeChat merchant refund | WeChat Pay | We::WePayRefund() |
Transfers.php | WePayTransfers | Pay to WeChat merchants in small change | WeChat Pay | We::WePayTransfers() |
TransfersBank.php | WePayTransfersBank | WeChat merchants transfer money to bank cards | WeChat Pay | We::WePayTransfersBank() |
Crypt.php | WeMiniCrypt | WeChat applet data encryption processing | WeChat applet | We::WeMiniCrypt() |
Plugs.php | WeMiniPlugs | WeChat mini program plug-in management | WeChat applet | We::WeMiniPlugs() |
Poi.php | WeMiniPoi | WeChat applet address management | WeChat applet | We::WeMiniPoi() |
Qrcode.php | WeMiniQrcode | WeChat Mini Program QR Code Management | WeChat applet | We::WeMiniCrypt() |
Template.php | WeMiniTemplate | WeChat mini program template message support | WeChat applet | We::WeMiniTemplate() |
Total.php | WeMiniTotal | WeChat applet data interface | WeChat applet | We::WeMiniTotal() |
1.1 Manage installation through Composer
# 首次安装 线上版本(稳定)
composer require zoujingli/wechat-developer
# 首次安装 开发版本(开发)
composer require zoujingli/wechat-developer dev-master
# 更新 WeChatDeveloper
composer update zoujingli/wechat-developer
1.2 If you do not use Composer, you can download WeChatDeveloper and extract it into the project
# 在项目中加载初始化文件
include "您的目录/WeChatDeveloper/include.php " ;
2.1 Parameters required for interface instances
// =====================================================
// 配置缓存处理函数 ( 适配其他环境 )
// -----------------------------------------------------
// 数据缓存 (set|get|del) 操作可以将缓存写到任意位置或Redis
// 文件缓存 (put) 只能写在本地服务器,还需要返回可读的文件路径
// 未配置自定义缓存处理机制时,默认在 cache_path 写入文件缓存
// // =====================================================
// WeChatContractsTools::$cache_callable = [
// 'set' => function ($name, $value, $expired = 360) {
// var_dump(func_get_args());
// return $value;
// },
// 'get' => function ($name) {
// var_dump(func_get_args());
// return $value;
// },
// 'del' => function ($name) {
// var_dump(func_get_args());
// return true;
// },
// 'put' => function ($name) {
// var_dump(func_get_args());
// return $filePath;
// },
// ];
$ config = [
' token ' => ' test ' ,
' appid ' => ' wx60a43dd8161666d4 ' ,
' appsecret ' => ' 71308e96a204296c57d7cd4b21b883e8 ' ,
' encodingaeskey ' => ' BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5 ' ,
// 配置商户支付参数(可选,在使用支付功能时需要)
' mch_id ' => " 1235704602 " ,
' mch_key ' => ' IKI4kpHjU94ji3oqre5zYaQMwLHuZPmj ' ,
// 配置商户支付双向证书目录(可选,在使用退款|打款|红包时需要)
' ssl_key ' => '' ,
' ssl_cer ' => '' ,
// 缓存目录配置(可选,需拥有读写权限)
' cache_path ' => '' ,
];
3.1 Instance-specific interface
try {
// 实例对应的接口对象
$ user = new WeChat User ( $ config );
// 调用接口对象方法
$ list = $ user -> getUserList ();
// 处理返回的结果
echo ' <pre> ' ;
var_export ( $ list );
} catch ( Exception $ e ) {
// 出错啦,处理下吧
echo $ e -> getMessage () . PHP_EOL ;
}
// 创建接口实例
$ wechat = new WeChat Pay ( $ config );
// 组装参数,可以参考官方商户文档
$ 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 ' ,
];
try {
// 生成预支付码
$ result = $ wechat -> createOrder ( $ options );
// 创建JSAPI参数签名
$ options = $ wechat -> createParamsForJsApi ( $ result [ ' prepay_id ' ]);
// @todo 把 $options 传到前端用js发起支付就可以了
} catch ( Exception $ e ) {
// 出错啦,处理下吧
echo $ e -> getMessage () . PHP_EOL ;
}
$ config = [
// 沙箱模式
' debug ' => true ,
// 签名类型 ( RSA|RSA2 )
' sign_type ' => ' RSA2 ' ,
// 应用ID
' appid ' => ' 2021000122667306 ' ,
// 应用私钥内容 ( 需1行填写,特别注意:这里的应用私钥通常由支付宝密钥管理工具生成 )
' private_key ' => ' MIIEowIBAAKCAQEAn... ' ,
// 公钥模式,支付宝公钥内容 ( 需1行填写,特别注意:这里不是应用公钥而是支付宝公钥,通常是上传应用公钥换取支付宝公钥,在网页可以复制 )
' public_key ' => '' ,
// 证书模式,应用公钥证书路径 ( 新版资金类接口转 app_cert_sn,如文件 appCertPublicKey.crt )
' app_cert_path ' => __DIR__ . ' /alipay/appPublicCert.crt ' , // 'app_cert' => '证书内容',
// 证书模式,支付宝根证书路径 ( 新版资金类接口转 alipay_root_cert_sn,如文件 alipayRootCert.crt )
' alipay_root_path ' => __DIR__ . ' /alipay/alipayRootCert.crt ' , // 'root_cert' => '证书内容',
// 证书模式,支付宝公钥证书路径 ( 未填写 public_key 时启用此参数,如文件 alipayPublicCert.crt )
' alipay_cert_path ' => __DIR__ . ' /alipay/alipayPublicCert.crt ' , // 'public_key' => '证书内容'
// 支付成功通知地址
' notify_url ' => '' ,
// 网页支付回跳地址
' return_url ' => '' ,
];
// 参考公共参数 https://docs.open.alipay.com/203/107090/
$ config [ ' notify_url ' ] = ' http://pay.thinkadmin.top/test/alipay-notify.php ' ;
$ config [ ' return_url ' ] = ' http://pay.thinkadmin.top/test/alipay-success.php ' ;
try {
// 实例支付对象
$ pay = We:: AliPayWeb ( $ config );
// $pay = new AliPayWeb($config);
// 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
$ result = $ pay -> apply ([
' out_trade_no ' => time (), // 商户订单号
' total_amount ' => ' 1 ' , // 支付金额
' subject ' => '支付订单描述' , // 支付订单描述
]);
echo $ result ; // 直接输出HTML(提交表单跳转)
} catch ( Exception $ e ) {
// 异常处理
echo $ e -> getMessage ();
}
// 参考公共参数 https://docs.open.alipay.com/203/107090/
$ config [ ' notify_url ' ] = ' http://pay.thinkadmin.top/test/alipay-notify.php ' ;
$ config [ ' return_url ' ] = ' http://pay.thinkadmin.top/test/alipay-success.php ' ;
try {
// 实例支付对象
$ pay = We:: AliPayWap ( $ config );
// $pay = new AliPayWap($config);
// 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
$ result = $ pay -> apply ([
' out_trade_no ' => time (), // 商户订单号
' total_amount ' => ' 1 ' , // 支付金额
' subject ' => '支付订单描述' , // 支付订单描述
]);
echo $ result ; // 直接输出HTML(提交表单跳转)
} catch ( Exception $ e ) {
// 异常处理
echo $ e -> getMessage ();
}
WeChatDeveloper is released under the MIT open source license and is available for free.
The copyright information of the third-party source code and binary files included in this project will be separately marked, please check it in the corresponding file.
Copyright Copyright © 2014-2023 by ThinkAdmin (https://thinkadmin.top) All rights reserved.