canuonifeng/omnipay-wechatpay
Composer 安装命令:
composer require canuonifeng/omnipay-wechatpay
包简介
Wechat gateway for Omnipay payment processing library
README 文档
README
- forked from lokielse/omnipay-wechatpay
- for PHP 5.3+
- add refunded notify
Installation
Omnipay is installed via Composer. To install, simply add it
to your composer.json file:
"codeages/omnipay-wechatpay": "^1.0",
And run composer to update your dependencies:
$ composer update -vvv
Basic Usage
The following gateways are provided by this package:
- WechatPay (Wechat Common Gateway) 微信支付通用网关
- WechatPay_App (Wechat App Gateway) 微信APP支付网关
- WechatPay_Native (Wechat Native Gateway) 微信原生扫码支付支付网关
- WechatPay_Js (Wechat Js API/MP Gateway) 微信网页、公众号、小程序支付网关
- WechatPay_Pos (Wechat Micro/POS Gateway) 微信刷卡支付网关
- WechatPay_Mweb (Wechat H5 Gateway) 微信H5支付网关
Usage
Create Order doc
//gateways: WechatPay_App, WechatPay_Native, WechatPay_Js, WechatPay_Pos, WechatPay_Mweb $gateway = Omnipay::create('WechatPay_App'); $gateway->setAppId($config['app_id']); $gateway->setMchId($config['mch_id']); $gateway->setApiKey($config['api_key']); $order = [ 'body' => 'The test order', 'out_trade_no' => date('YmdHis').mt_rand(1000, 9999), 'total_fee' => 1, //=0.01 'spbill_create_ip' => 'ip_address', 'fee_type' => 'CNY' ]; /** * @var Omnipay\WechatPay\Message\CreateOrderRequest $request * @var Omnipay\WechatPay\Message\CreateOrderResponse $response */ $request = $gateway->purchase($order); $response = $request->send(); //available methods $response->isSuccessful(); $response->getData(); //For debug $response->getAppOrderData(); //For WechatPay_App $response->getJsOrderData(); //For WechatPay_Js $response->getCodeUrl(); //For Native Trade Type
Notify doc
$gateway = Omnipay::create('WechatPay'); $gateway->setAppId($config['app_id']); $gateway->setMchId($config['mch_id']); $gateway->setApiKey($config['api_key']); $response = $gateway->completePurchase([ 'request_params' => file_get_contents('php://input') ])->send(); if ($response->isPaid()) { //pay success var_dump($response->getRequestData()); }else{ //pay fail }
Query Order doc
$response = $gateway->query([ 'transaction_id' => '1217752501201407033233368018', //The wechat trade no ])->send(); var_dump($response->isSuccessful()); var_dump($response->getData());
Close Order doc
$response = $gateway->close([ 'out_trade_no' => '201602011315231245', //The merchant trade no ])->send(); var_dump($response->isSuccessful()); var_dump($response->getData());
Refund doc
$gateway->setCertPath($certPath); $gateway->setKeyPath($keyPath); $response = $gateway->refund([ 'transaction_id' => '1217752501201407033233368018', //The wechat trade no 'out_refund_no' => $outRefundNo, 'total_fee' => 1, //=0.01 'refund_fee' => 1, //=0.01 ])->send(); var_dump($response->isSuccessful()); var_dump($response->getData());
Refund Notify doc
$gateway = Omnipay::create('WechatPay'); $gateway->setAppId($config['app_id']); $gateway->setMchId($config['mch_id']); $gateway->setApiKey($config['api_key']); $response = $gateway->completeRefund([ 'request_params' => file_get_contents('php://input') ])->send(); if ($response->isRefunded()) { //pay success var_dump($response->getRequestData()); }else{ //pay fail }
QueryRefund doc
$response = $gateway->queryRefund([ 'refund_id' => '1217752501201407033233368018', //Your site trade no, not union tn. ])->send(); var_dump($response->isSuccessful()); var_dump($response->getData());
Shorten URL (for WechatPay_Native) doc
$response = $gateway->shortenUrl([ 'long_url' => $longUrl ])->send(); var_dump($response->isSuccessful()); var_dump($response->getData()); var_dump($response->getShortUrl());
Query OpenId (for WechatPay_Pos) doc
$response = $gateway->shortenUrl([ 'auth_code' => $authCode ])->send(); var_dump($response->isSuccessful()); var_dump($response->getData()); var_dump($response->getOpenId());
For general usage instructions, please see the main Omnipay repository.
canuonifeng/omnipay-wechatpay 适用场景与选型建议
canuonifeng/omnipay-wechatpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.78k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「payment」 「pay」 「sdk」 「gateway」 「app」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 canuonifeng/omnipay-wechatpay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 canuonifeng/omnipay-wechatpay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 canuonifeng/omnipay-wechatpay 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Payyo Gateway for the Omnipay payment processing library
Библиотека для приема платежей через Альфабанк.
Some pre-defined rules for validation in Omnipay payment processing library.
BluePay gateway for the Omnipay payment processing library
支付宝接口扩展包
Alfabank REST API integration
统计信息
- 总下载量: 1.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-12