定制 ccob/omnipay-wechatpay 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ccob/omnipay-wechatpay

Composer 安装命令:

composer require ccob/omnipay-wechatpay

包简介

Wechatpay gateway for Omnipay payment processing library

README 文档

README

Installation

To install, simply add it to your composer.json file:

{
    "require": {
        "ccob/omnipay-wechatpay": "dev-master"
    }
}

Usage

Create unified order

use Omnipay\Omnipay;

$gateway = Omnipay::create( 'WechatPay' );
$gateway->setAppId( 'Your appid here.' );
$gateway->setMchId( 'Your mch_id here.' );
$gateway->setKey( 'Your key for WeChat payment here.' );
$gateway->setTradeType( 'JSAPI' );
$gateway->setAttach( 'test' );
$gateway->setBody( 'test' );
$gateway->setGoodsTag( 'test' );
$gateway->setOutTradeNo( 'Unique order id in your site.' );
$gateway->setTotalFee( 1 );
$gateway->setSpbillCreateIP( Request::ip() );
$gateway->setNotifyUrl( 'http://test.com/pay/notify' );

$response = $gateway->createUnifiedOrder()->send(); // Get prepay_id, code_url etc.

$package = $response->createWebPaymentPackage(); // Get payment parameters for web

Validate notification parameters

You can validate parameters as follow:

use Omnipay\Omnipay;

$request_content = file_get_contents('php://input');
$gateway = Omnipay::create( 'WechatPay' );
$gateway->setKey( 'Your key for WeChat payment here.' );

$complete_request = $gateway->completeOrder( $request_content );  // Auto convert xml string to array

$complete_response = $complete_request->send();
$complete_response->isResultSuccessful();
$complete_response->isResponseSuccessful();

/**
 * Would get xml string followed while function 'isResultSuccessful' return Boolean true:
 *    <xml><return_code><![CDATA[SUCCESS]]></return_code></xml>
 * Or string followed while false
 *    <xml><return_code><![CDATA[FAIL]]></return_code></xml>
 */
$complete_response->getResponseText();

Or use it as follow. But example above is recommended.

use Omnipay\Omnipay;

$request_content = file_get_contents('php://input');
$request_params = json_decode(json_encode(simplexml_load_string($request->getContent(), 'SimpleXMLElement', LIBXML_NOCDATA)), true);

$gateway = Omnipay::create( 'WechatPay' );
$gateway->setKey( 'Your key for WeChat payment here.' );

$complete_request = $gateway->completeOrder(array( 
  'request_params' => $request_params 
));

$complete_response = $complete_request->send();
$complete_response->isResultSuccessful();
$complete_response->isResponseSuccessful();
$complete_response->getResponseText();

Query order

use Omnipay\Omnipay;

$gateway = Omnipay::create( 'WechatPay' );
$gateway->setAppId( 'Your appid here.' );
$gateway->setMchId( 'Your mch_id here.' );
$gateway->setKey( 'Your key for WeChat payment here.' );
$request = $gateway->queryOrder([
    'transaction_id'   => 'Transaction id created by wechat'
]);

$response = $request->send();

$response->getOpenId(),
$response->isSubscribe(),
$response->getTradeType(),
$response->getBankType(),
$response->getTotalFee(),
$response->getFeeType(),
$response->getTransactionId(),
$response->getOutTradeNo(),
$response->getAttach(),
$response->getTimeEnd(),
$response->getTradeState(),
$response->getCashFee(),
$response->getTradeStateDesc()

Refund

use Omnipay\Omnipay;

$gateway = Omnipay::create( 'Your appid here.' );
$gateway->setAppId( 'Your appid here.' );
$gateway->setMchId( 'Your mch_id here.' );
$gateway->setKey( 'Your key for WeChat payment here.' );

$request = $gateway->createRefund([
    'ssl_cert_path'     =>  storage_path() . '/cert/apiclient_cert.pem',
    'ssl_key_path'      =>  storage_path() . '/cert/apiclient_key.pem',
    'transaction_id'    =>  '111111111111',
    'out_trade_no'      =>  '222222222222',
    'out_refund_no'     =>  '333333333333',
    'total_fee'         =>  50,
    'refund_fee'        =>  20,
    'op_user_id'        =>  'Your mch_id here.'
]);

$response = $request->send();
$response->isResponseSuccessful();
$response->isSignatureMatched();
$response->isResultSuccessful();

Query refund

use Omnipay\Omnipay;

$gateway = Omnipay::create( 'WechatPay' );
$gateway->setAppId( 'Your appid here.' );
$gateway->setMchId( 'Your mch_id here.' );
$gateway->setKey( 'Your key for WeChat payment here.' );

/**
 * One of 'transaction_id', 'out_trade_no', 'out_refund_no', 'refund_id' is required
 */
$request = $gateway->queryRefund([
    'transaction_id'    => '11111111',
    'out_trade_no'      => '22222222',
    'out_refund_no'     => '33333333',
    'refund_id'         => '44444444'
]);

$response = $request->send();
$response->isResultSuccessful();
$response->isResponseSuccessful();
$response->isSignatureMatched();
$response->getTransactionId();
$response->getOutTradeNo();
$response->getRefundFee();
$response->getRefundCount();
$response->getNthOutRefundNo( N );      // 0 <= N < getRefundCount()
$response->getNthRefundId( N );         // 0 <= N < getRefundCount()
$response->getNthRefundFee( N );        // 0 <= N < getRefundCount()
$response->getNthRefundStatus( N );     // 0 <= N < getRefundCount()
$response->getNthRefundChannel( N );    // 0 <= N < getRefundCount()

ccob/omnipay-wechatpay 适用场景与选型建议

ccob/omnipay-wechatpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 55 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「pay」 「gateway」 「merchant」 「purchase」 「omnipay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ccob/omnipay-wechatpay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ccob/omnipay-wechatpay 我们能提供哪些服务?
定制开发 / 二次开发

基于 ccob/omnipay-wechatpay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 55
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-06