├── .gitattributes ├── LICENSE ├── README.md ├── coinbase.png ├── coinpay.html └── coinpay └── coinpay.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 huangfengye 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoinbaseForZfaka 2 | ## 支持收取BTC,BCH,DAI,dogocoin,ETH,LTC,USDC 3 | 4 | ## 安装 5 | + 按照https://github.com/zlkbdotnet/zfaka 要求安装zfaka,建议使用页面中提示的宝塔教程进行安装,省时省力 6 | 7 | + 注册Coinbase商家版 https://commerce.coinbase.com/signup 8 | + 进入Coinbase商家版面板设置页面 https://commerce.coinbase.com/dashboard 9 | + 找到 Creat an Api Key,点击一下,创建一个Api Key. 10 | + 找到Webhook Subscriptions ,点击Add a endpoint,填入自己的异步回调地址: https://你的卡网域名/product/notify/?paymethod=coinpay 11 | + 点击回调地址 右边的Details,在弹出的窗口中 Events--->Edit, 在所有Events中仅仅勾选 charge:confirmed,然后点击保存 12 | + 找到Webhook subscriptions 下的Show shared secret,点击它,保存下其中的共享密钥 13 | 14 | 15 | + 将文件夹 coinpay 解压到网站目录application/library/Pay文件夹中,此时在Pay文件夹中会多出一个文件夹,名字分别为:coinpay 16 | 17 | + 将文件 coinpay.html 解压到网站目录application\modules\Admin\views\payment\tpl文件夹中 (注意,如果你更改过后台路径,请把这段目录地址中的Admin替换成你的自己的地址) 18 | 19 | + 将coinbase.png 拷贝到网站目录/public/res/images/pay中 20 | 21 | + 修改数据库,在faka数据库中运行下面的sql语句,建议使用宝塔环境的phpmyadmin软件进行修改,省时省力 22 | ``` 23 | INSERT INTO `t_payment` (`payment`, `payname`, `payimage`, `alias`, `sign_type`, `app_id`, `app_secret`, `ali_public_key`, `rsa_private_key`, `configure3`, `configure4`, `overtime`, `active`) VALUES 24 | ('CoinPay', 'CoinPay', '/res/images/pay/coinbase.png', 'coinpay', 'MD5', '', '', '', '', '', '', 6000, 0); 25 | ``` 26 | + 登录zfaka的后台,依次点击:设置中心->配置中心,在第三页修改参数“weburl”的值为你自己的网站域名url(必须修改,否则无法回调) 27 | 28 | + 依次点击:设置中心->支付设置,修改编辑“CoinPay”支付渠道,将你之前创建的Api Key通信密钥填入API密钥进去,shared secret填入共享密钥,设置自己的需要的费率,选中激活状态,点击确认修改 29 | 30 | + 按照zfaka的后台逻辑,自行添加商品,自行测试 31 | 32 | ## 付费服务 33 | 如果你不会设置,可以联系我QQ583648414(或者414981146),提供设置服务😁 80元一次. 34 | ## 赞助 35 | 如果您有经济条件,您可以赞助本项目的开发(下方收款码),如果您不想赞助,也请您点击上面的Star给一个星星,也是对我莫大的认同,感谢各位的支持。 36 | 37 | ![微信赞助](https://puu.sh/DF0jt/ded5938c8c.jpg)![支付宝赞助](https://puu.sh/DEYmS/32f8237fd8.jpg) 38 | 39 | ## 感谢 40 | - https://github.com/huangfengye 集成此接口 41 | - 感谢https://github.com/zlkbdotnet/zfaka 提供的发卡方案 42 | -------------------------------------------------------------------------------- /coinbase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangfengye/CoinbaseForZfaka/31c2dca4f61f3eb554d3639a2865f0bb5b68c941/coinbase.png -------------------------------------------------------------------------------- /coinpay.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 |
6 | 10 |
11 |
12 |
13 |

注意事项:

14 |

本支付接口同步支付回调地址(第一种):/product/query/?zlkbmethod=auto&paymethod=&orderid={订单号}

15 |

本支付接口同步支付回调地址(第二种):/query/auto/{订单号}.html

16 |

本支付接口异步支付回调地址:/product/notify/?paymethod=

17 |
18 |
19 |
20 | 21 |
22 | 23 |
24 |
25 |
26 | 27 |
28 | 29 |
30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 |
38 |
39 | 40 |
41 | 42 |
43 |
44 |
45 | 46 |
47 | 48 |
49 |
默认为0.00,实际支付价格为:定价*(1+手续费),比如定价100,手续费0.05,买家实际应支付105;
50 |
51 |
52 | 53 |
54 | checked=""> 55 | checked=""> 56 |
57 |
58 |
59 | 60 |
61 | 62 |
63 |
64 |
65 | 66 | 67 | 68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | 76 | 77 | -------------------------------------------------------------------------------- /coinpay/coinpay.php: -------------------------------------------------------------------------------- 1 | 0.00) 25 | { 26 | $price_amount =(double)$params['money'] * (1.00+$fees);// 价格 * (1 + 0.05) 27 | } 28 | else 29 | { 30 | $price_amount =(double)$params['money']; 31 | } 32 | 33 | $price_amount = sprintf('%.2f', $price_amount);// 只取小数点后两位 34 | 35 | $redirect_url = $params['weburl']. "/query/auto/{$params['orderid']}.html"; //同步地址 36 | $cancel_url = $params['weburl']. "/query/auto/{$params['orderid']}.html"; //同步地址 37 | 38 | $config = [ 39 | 'name'=>$params['productname'], 40 | 'description'=>$params['productname'].'需付款'.$price_amount.'元', 41 | 'pricing_type' => 'fixed_price', 42 | 'local_price' => [ 43 | 'amount' => $price_amount, 44 | 'currency' => 'CNY' 45 | ], 46 | 'metadata' => [ 47 | 'customer_id' => $params['orderid'], 48 | 'customer_name' => $params['productname'] 49 | ], 50 | 'redirect_url' =>$redirect_url, 51 | 'cancel_url'=> $cancel_url 52 | ]; 53 | 54 | $header = array(); 55 | $header[] = 'Content-Type:application/json'; 56 | $header[] = 'X-CC-Api-Key:'.$payconfig['app_secret']; //APP key 57 | $header[] = 'X-CC-Version: 2018-03-22'; 58 | 59 | 60 | $createOrderUrl = $this->apiHost; 61 | 62 | $ch = curl_init(); //使用curl请求 63 | curl_setopt($ch, CURLOPT_URL, $createOrderUrl); 64 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 65 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 66 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 67 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($config)); 68 | $coinpay_json = curl_exec($ch); 69 | curl_close($ch); 70 | 71 | $coinpay_date=json_decode($coinpay_json,true); 72 | 73 | if(is_array($coinpay_date)) 74 | { 75 | { 76 | $JumpUrl = $coinpay_date['data']['hosted_url']; 77 | $closetime = 6000; 78 | $result = array('type'=>1,'subjump'=>0,'url'=>$JumpUrl,'paymethod'=>$this->paymethod,'payname'=>$payconfig['payname'],'overtime'=>$closetime,'money'=>$price_amount); 79 | return array('code'=>1,'msg'=>'success','data'=>$result); 80 | } 81 | }else 82 | { 83 | return array('code'=>1001,'msg'=>"支付接口请求失败",'data'=>''); 84 | } 85 | } 86 | catch (\Exception $e) 87 | { 88 | return array('code'=>1000,'msg'=>$e->getMessage(),'data'=>''); 89 | } 90 | } 91 | 92 | 93 | //处理返回 94 | public function notify($payconfig) 95 | { 96 | $payload = file_get_contents( 'php://input' ); 97 | 98 | $sig = $_SERVER['HTTP_X_CC_WEBHOOK_SIGNATURE']; 99 | 100 | $secret = $payconfig['configure3']; 101 | 102 | $sig2 = hash_hmac( 'sha256', $payload, $secret ); 103 | 104 | if ( ! empty( $payload ) && ($sig === $sig2) ) 105 | { 106 | $data = json_decode( $payload, true ); 107 | $event_data = $data['event']['data']; 108 | 109 | 110 | foreach ($event_data['payments'] as $payment) { 111 | if (strtolower($payment['status']) === 'confirmed') { 112 | $return_pay_amount = $payment['value']['local']['amount']; 113 | $return_currency=$payment['value']['local']['currency']; 114 | $return_status=strtolower($payment['status']); 115 | } 116 | } 117 | if($return_currency !== 'CNY') 118 | { 119 | return 'error|Notify: Wrong currency:'.$return_currency; 120 | } 121 | else 122 | { 123 | $return_merchant_order_id = $event_data['metadata']['customer_id'];//商户订单号 124 | $tradeid = $event_data['code']; 125 | 126 | if($return_status === 'confirmed') 127 | { 128 | $config = array('paymethod' => $this->paymethod, 'tradeid' => $tradeid, 'paymoney' => $return_pay_amount, 'orderid'=>$return_merchant_order_id ); 129 | $notify = new \Pay\notify(); 130 | $data = $notify->run($config); 131 | if ($data['code'] > 1) { 132 | return 'error|Notify: ' . $data['msg'] ; 133 | } 134 | else 135 | { 136 | return 'success'; 137 | } 138 | } 139 | else 140 | { 141 | return 'error|Notify: status not completed :'.$return_status; 142 | } 143 | 144 | } 145 | } 146 | else { //合法的数据 147 | //业务处理 148 | return 'error|Notify: auth Fail'.$payload.'='.$sig.'='.$sig2.'='.$XCCWebhookSignature; 149 | } 150 | } 151 | 152 | 153 | } 154 | --------------------------------------------------------------------------------