scottchayaa/allpay 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

scottchayaa/allpay

Composer 安装命令:

composer require scottchayaa/allpay

包简介

Allpay - Laravel 5 version

关键字:

README 文档

README

step 1 : Download the package

composer命令安裝

composer require scottchayaa/allpay dev-master

或者是新增package至composer.json

"require": {
  "scottchayaa/allpay": "dev-master"
},

然後更新安裝

composer update

或全新安裝

composer install

step 2 : Modify config file

增加config/app.php中的providersaliases的參數

'providers' => [
  // ...
  ScottChayaa\Allpay\AllpayServiceProvider::class,
]

'aliases' => [
  // ...
  'Allpay' => ScottChayaa\Allpay\Facade\Allpay::class,
]

step 3 : Publish config to your project

執行下列命令,將package的config檔配置到你的專案中

php artisan vendor:publish

可至config/allpay.php中查看
預設是Allpay的測試環境設定

return [
    'ServiceURL' => 'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut',
    'HashKey'    => '5294y06JbISpM5x9',
    'HashIV'     => 'v77hoKGq4kWxNNIS',
    'MerchantID' => '2000132',
];

How To Use

use Allpay;

public function Demo()
{
    //Official Example : 
    //https://github.com/allpay/PHP/blob/master/AioSDK/example/sample_Credit_CreateOrder.php
    
    //基本參數(請依系統規劃自行調整)
    Allpay::i()->Send['ReturnURL']         = "http://www.allpay.com.tw/receive.php" ;
    Allpay::i()->Send['MerchantTradeNo']   = "Test".time() ;           //訂單編號
    Allpay::i()->Send['MerchantTradeDate'] = date('Y/m/d H:i:s');      //交易時間
    Allpay::i()->Send['TotalAmount']       = 2000;                     //交易金額
    Allpay::i()->Send['TradeDesc']         = "good to drink" ;         //交易描述
    Allpay::i()->Send['ChoosePayment']     = \PaymentMethod::ALL ;     //付款方式

    //訂單的商品資料
    array_push(Allpay::i()->Send['Items'], array('Name' => "歐付寶黑芝麻豆漿", 'Price' => (int)"2000",
               'Currency' => "", 'Quantity' => (int) "1", 'URL' => "dedwed"));

    //Go to AllPay
    echo "歐付寶頁面導向中...";
    echo Allpay::i()->CheckOutString();
}

用laravel的人開發盡量使用CheckOutString()回傳String的方法
當然使用CheckOut()也是可以
但如果使用的話,我猜後面可能會碰到Get不到特定Session的問題

PS : PaymentMethod前面一定要加反斜線 \ → 這目前我也沒辦法,如果有人知道怎麼樣可以不用加,請告訴我
You Need to add Backslash '' before PaymentMethod → I have no idea how to take it off. If someone know how to remove, please tell me how to do. thx~

Example (Localhost)

Example Link : http://localhost/[your-project]/public/allpay_demo_201608

Bug Fix Record

AllPay.Payment.Integration.php : (Latest commit e9278b9)
https://github.com/allpay/PHP/commit/e9278b9cad76e6a71608bee3f5f4289982cfe16f

1) 修正 CheckOutString

原檔

static function CheckOutString($paymentButton,$target = "_self",$arParameters = array(),$arExtend = array(),$HashKey='',$HashIV='',$ServiceURL=''){
    
    $arParameters = self::process($arParameters,$arExtend);
    //產生檢查碼
    $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$arParameters['EncryptType']);
    
    $szHtml =  '<!DOCTYPE html>';
    $szHtml .= '<html>';
    $szHtml .=     '<head>';
    $szHtml .=         '<meta charset="utf-8">';
    $szHtml .=     '</head>';
    $szHtml .=     '<body>';
    $szHtml .=         "<form id=\"__allpayForm\" method=\"post\" target=\"{$target}\" action=\"{$ServiceURL}\">";
    foreach ($arParameters as $keys => $value) {
        $szHtml .=         "<input type=\"hidden\" name=\"{$keys}\" value='{$value}' />";
    }
    $szHtml .=             "<input type=\"hidden\" name=\"CheckMacValue\" value=\"{$szCheckMacValue}\" />";
    $szHtml .=             "<input type=\"submit\" id=\"__paymentButton\" value=\"{$paymentButton}\" />";
    $szHtml .=         '</form>';
    $szHtml .=     '</body>';
    $szHtml .= '</html>';
    return  $szHtml ;
}

修正為

static function CheckOutString($paymentButton,$target = "_self",$arParameters = array(),$arExtend = array(),$HashKey='',$HashIV='',$ServiceURL=''){
    
    $arParameters = self::process($arParameters,$arExtend);
    //產生檢查碼
    $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$arParameters['EncryptType']);
    
    $szHtml =  '<!DOCTYPE html>';
    $szHtml .= '<html>';
    $szHtml .=     '<head>';
    $szHtml .=         '<meta charset="utf-8">';
    $szHtml .=     '</head>';
    $szHtml .=     '<body>';
    $szHtml .=         "<form id=\"__allpayForm\" method=\"post\" target=\"{$target}\" action=\"{$ServiceURL}\">";

    foreach ($arParameters as $keys => $value) {
        $szHtml .=         "<input type=\"hidden\" name=\"{$keys}\" value='{$value}' />";
    }

    $szHtml .=             "<input type=\"hidden\" name=\"CheckMacValue\" value=\"{$szCheckMacValue}\" />";
    if (!isset($paymentButton)) {
        $szHtml .=  '<script type="text/javascript">document.getElementById("__allpayForm").submit();</script>';
    }
    else{
        $szHtml .=  "<input type=\"submit\" id=\"__paymentButton\" value=\"{$paymentButton}\" />";
    }
    $szHtml .=         '</form>';
    $szHtml .=     '</body>';
    $szHtml .= '</html>';
    return  $szHtml ;
}

主要是針對$paymentButton去做調整
如果有比較現在版本跟以前版本的人會發現這個錯誤
缺少if (!isset($paymentButton))的判斷
如果官方的工程師有發現這個問題就趕快解吧

2) 修正CheckOutFeedback

原檔

function CheckOutFeedback() {
    return $arFeedback = CheckOutFeedback::CheckOut($_POST,$this->HashKey,$this->HashIV,0);   
}

修正為

function CheckOutFeedback($allPost = null) {
    if($allPost == null) $allPost = $_POST;
    return $arFeedback = CheckOutFeedback::CheckOut($allPost,$this->HashKey,$this->HashIV,0);   
}

歐付寶回傳頁面時會使用到這個方法
使用方法 ex:

public function PayReturn(Request $request)
{
    /* 取得回傳參數 */
    $arFeedback = Allpay::i()->CheckOutFeedback($request->all());
    //...
}

注意要傳入$request->all()
因為官方原本的方法是帶入$_POST → Laravel 5 不鳥你這個,所以會出錯
固做此修正
不過這部分沒有多做說明,留給大家試試看  

scottchayaa/allpay 适用场景与选型建议

scottchayaa/allpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 559 次下载、GitHub Stars 达 13, 最近一次更新时间为 2016 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 scottchayaa/allpay 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-08-11