ThinkPHP5.0串接台湾绿界ECPAY支付|站内付2.0

本文介绍了如何在PHP项目中集成绿界ECPAY2.0支付SDK,包括下载SDK、配置依赖、创建支付控制器以及处理付款回传的处理逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近项目需要接入绿界ECPAY支付站内2.0版本

下载Sdk

进入ecpay开发者中心,下载对应的SDK,项目使用的PHP语言,对应下载PHP_SDK
在这里插入图片描述
上传目录下面src文件夹到根目录,修改项目根目录composer.json,增加如下粗体代码

**"require-dev": {
    "phpunit/phpunit": "^5.0 || ^6.0 || ^7.0 || ^8.0",
    "fzaninotto/faker": "1.9.x-dev"
},**
"autoload": {
    "psr-4": {
        "app\\": "application",
        **"Ecpay\\Sdk\\": "src/"**
    }
},

项目根目录打开命令行,安装依赖

composer install

创建控制器,通过命名空间引入

use Ecpay\Sdk\Factories\Factory; 

class Payment extends Controller
{
	private $factory;
	public function _initialize(){
		 $this->factory=new Factory([
            'hashKey' => '你自己申请的hashKey',
            'hashIv' => '你自己申请的hashIv',
        ]);
	}
}

其他部分参考SDK中的案例就可以

关于绿界付款回传

$.post(url + '/Payment/createOrder', { payToken: _payToken, merchantTradeNo: MerchantTradeNo }, function(response) {
     console.log("response",response)
      if(response.Data.ThreeDInfo.ThreeDURL){
      	//跳转OTP页面
      	location.href=response.Data.ThreeDInfo.ThreeDURL
      }
      if(response.Data.CVSInfo.PaymentURL){
      	//跳转超商代码页面
      	location.href=response.Data.CVSInfo.PaymentURL
      }

      if(response.Data.BarcodeInfo){
      	//超商条码需要手动在页面生成条码
	      	$(".barCode").empty().append(`<div><img src='/Order/barCode?barCode=${response.Data.BarcodeInfo.Barcode1}'/><span>${response.Data.BarcodeInfo.Barcode1}</span></div><div><img src='/Order/barCode?barCode=${response.Data.BarcodeInfo.Barcode2}'/><span>${response.Data.BarcodeInfo.Barcode2}</span></div><div><img src='/Order/barCode?barCode=${response.Data.BarcodeInfo.Barcode3}'/><span>${response.Data.BarcodeInfo.Barcode3}</span></div>`)
      }
      
  }, 'json');
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值