first commit
This commit is contained in:
70
vendor/uduncloud/udun-wallet-sdk/src/Api.php
vendored
Normal file
70
vendor/uduncloud/udun-wallet-sdk/src/Api.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace Udun\Dispatch;
|
||||
use Hanson\Foundation\AbstractAPI;
|
||||
class Api extends AbstractAPI
|
||||
{
|
||||
//商户号
|
||||
protected $merchant_no;
|
||||
//apikey
|
||||
protected $api_key;
|
||||
//节点地址
|
||||
protected $gateway_address;
|
||||
//回调地址
|
||||
protected $callUrl;
|
||||
public function __construct( $merchant_no, string $api_key,string $gateway_address, string $callUrl)
|
||||
{
|
||||
$this->merchant_no = $merchant_no;
|
||||
$this->api_key = $api_key;
|
||||
$this->gateway_address = $gateway_address;
|
||||
$this->callUrl = $callUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param array $params
|
||||
* @return result
|
||||
* @throws UdunDispatchException
|
||||
*/
|
||||
public function request(string $method, array $body)
|
||||
{
|
||||
$time = time();
|
||||
$nonce = rand(100000, 999999);
|
||||
if($method=='/mch/support-coins'){
|
||||
$body = json_encode($body);
|
||||
}else{
|
||||
$body = '['.json_encode($body).']';
|
||||
}
|
||||
|
||||
$sign = $this->signature($body,$time,$nonce);
|
||||
$params = array(
|
||||
'timestamp' => $time,
|
||||
'nonce' => $nonce,
|
||||
'sign' => $sign,
|
||||
'body' => $body
|
||||
);
|
||||
$http = $this->getHttp();
|
||||
$response = $http->json($this->gateway_address. $method, $params);
|
||||
$result = json_decode(strval($response->getBody()), true);
|
||||
$this->checkErrorAndThrow($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function signature($body,$time,$nonce)
|
||||
{
|
||||
return md5($body.$this->api_key.$nonce.$time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
* @throws UdunDispatchException
|
||||
*/
|
||||
private function checkErrorAndThrow($result)
|
||||
{
|
||||
if (!$result || $result['code'] != 200) {
|
||||
throw new UdunDispatchException($result['code'], $result['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
162
vendor/uduncloud/udun-wallet-sdk/src/Clients.php
vendored
Normal file
162
vendor/uduncloud/udun-wallet-sdk/src/Clients.php
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
namespace Udun\Dispatch;
|
||||
class Clients extends Api
|
||||
{
|
||||
// 获取商户支持的币种信息
|
||||
/**
|
||||
* showBalance Boolean 是否查詢余額,false不獲取,true獲取
|
||||
* */
|
||||
public function supportCoins($showBalance = true)
|
||||
{
|
||||
$body = array(
|
||||
'merchantId' => $this->merchant_no,//商户号
|
||||
'showBalance' => $showBalance
|
||||
);
|
||||
return $this->request('/mch/support-coins', $body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建地址
|
||||
* mainCoinType 主币种编号
|
||||
* walletId 錢包編號,默認根據主錢包生成地址
|
||||
* alias 地址別名
|
||||
*/
|
||||
public function createAddress($mainCoinType,$walletId=null,$alias=null)
|
||||
{
|
||||
$body = array(
|
||||
'merchantId' => $this->merchant_no,
|
||||
'mainCoinType' => $mainCoinType,
|
||||
'callUrl' => $this->callUrl
|
||||
);
|
||||
if(!empty($walletId)){
|
||||
$body['walletId']=$walletId;
|
||||
}
|
||||
if(!empty($alias)){
|
||||
$body['alias']=$alias;
|
||||
}
|
||||
return $this->request('/mch/address/create', $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证地址的合法性
|
||||
* mainCoinType 主币种编号
|
||||
* address 地址
|
||||
*
|
||||
* */
|
||||
public function checkAddress($mainCoinType,$address)
|
||||
{
|
||||
$body = array(
|
||||
'merchantId' => $this->merchant_no,//商户号
|
||||
'mainCoinType' => $mainCoinType,
|
||||
'address' => $address
|
||||
);
|
||||
return $this->request('/mch/check/address', $body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证地址是否存在
|
||||
* mainCoinType 主币种编号
|
||||
* address 地址
|
||||
*
|
||||
* */
|
||||
public function existAddress($mainCoinType,$address)
|
||||
{
|
||||
$body = array(
|
||||
'merchantId' => $this->merchant_no,//商户号
|
||||
'mainCoinType' => $mainCoinType,
|
||||
'address' => $address
|
||||
);
|
||||
return $this->request('/mch/exist/address', $body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 申请提币
|
||||
* businessId 业务编号,必须唯一
|
||||
* mainCoinType 主币种编号
|
||||
* coinType 子币种编号
|
||||
* address 地址
|
||||
* amount 提币数量
|
||||
* memo 备注
|
||||
* */
|
||||
public function withdraw($businessId,$mainCoinType,$coinType,$address,$amount,$memo='')
|
||||
{
|
||||
$body = array(
|
||||
'merchantId' => $this->merchant_no,//商户号
|
||||
'mainCoinType' => $mainCoinType,
|
||||
'coinType' => $coinType,
|
||||
'address' => $address,
|
||||
'businessId' => $businessId,
|
||||
'amount' => $amount,
|
||||
'callUrl' => $this->callUrl //回调地址
|
||||
);
|
||||
if(!empty($memo)){
|
||||
$body['memo']=$memo;
|
||||
}
|
||||
return $this->request('/mch/withdraw', $body);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//自定义日志
|
||||
function printLog($msg) {
|
||||
if (!is_dir('log')){
|
||||
mkdir('log',0777,true);
|
||||
}
|
||||
$path="log/".date('Y-m-d').".log";
|
||||
file_put_contents($path, "【" . date('Y-m-d H:i:s') . "】" . $msg . "\r\n\r\n", FILE_APPEND);
|
||||
}
|
||||
//回调函数
|
||||
public function callback(){
|
||||
$body = $_POST['body'];
|
||||
$nonce = $_POST['nonce'];
|
||||
$timestamp = $_POST['timestamp'];
|
||||
$sign = $_POST['sign'];
|
||||
//接收回调参数 用于日志记录
|
||||
//$content = file_get_contents('php://input');
|
||||
//$this->printLog("回调接收内容:".$content);
|
||||
//验证签名
|
||||
$signCheck = $this->signature($body,$timestamp,$nonce);
|
||||
if ($sign != $signCheck) {
|
||||
throw new UdunDispatchException(-1, '签名错误');
|
||||
return ;
|
||||
}
|
||||
$body = json_decode($body);
|
||||
//$this->printLog("回调接收内容(tradeType):".$body->tradeType);
|
||||
//$body->tradeType 1充币回调 2提币回调
|
||||
if ($body->tradeType == 1) {
|
||||
|
||||
//$body->status 0待审核 1审核成功 2审核驳回 3交易成功 4交易失败
|
||||
if($body->status == 3){
|
||||
//业务处理
|
||||
}
|
||||
//无论业务方处理成功与否(success,failed),回调都认为成功
|
||||
return "success";
|
||||
|
||||
} elseif ($body->tradeType == 2) {
|
||||
|
||||
//$body->status 0待审核 1审核成功 2审核驳回 3交易成功 4交易失败
|
||||
if($body->status == 0){
|
||||
//业务处理
|
||||
}
|
||||
else if($body->status == 1){
|
||||
//业务处理
|
||||
}
|
||||
else if($body->status == 2){
|
||||
//业务处理
|
||||
}
|
||||
else if($body->status == 3){
|
||||
//业务处理
|
||||
}
|
||||
else if($body->status == 4){
|
||||
//业务处理
|
||||
}
|
||||
//无论业务方处理成功与否(success,failed),回调都认为成功
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
26
vendor/uduncloud/udun-wallet-sdk/src/ClientsServiceProvider.php
vendored
Normal file
26
vendor/uduncloud/udun-wallet-sdk/src/ClientsServiceProvider.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Udun\Dispatch;
|
||||
|
||||
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
|
||||
class ClientsServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Registers services on the given container.
|
||||
*
|
||||
* This method should only be used to configure services and parameters.
|
||||
* It should not get services.
|
||||
*
|
||||
* @param Container $pimple A container instance
|
||||
*/
|
||||
public function register(Container $pimple)
|
||||
{
|
||||
$pimple['clients'] = function ($pimple) {
|
||||
return new Clients($pimple['config']->get('merchant_no'), $pimple['config']->get('api_key'), $pimple['config']->get('gateway_address'), $pimple['config']->get('callUrl'));
|
||||
};
|
||||
}
|
||||
}
|
||||
28
vendor/uduncloud/udun-wallet-sdk/src/UdunDispatch.php
vendored
Normal file
28
vendor/uduncloud/udun-wallet-sdk/src/UdunDispatch.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Udun\Dispatch;
|
||||
|
||||
use Hanson\Foundation\Foundation;
|
||||
|
||||
|
||||
class UdunDispatch extends Foundation
|
||||
{
|
||||
|
||||
private $clients;
|
||||
|
||||
protected $providers = [
|
||||
ClientsServiceProvider::class
|
||||
];
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
$this->clients = new Clients($config['merchant_no'], $config['api_key'], $config['gateway_address'], $config['callUrl']);
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
return $this->clients->{$name}(...$arguments);
|
||||
}
|
||||
}
|
||||
11
vendor/uduncloud/udun-wallet-sdk/src/UdunDispatchException.php
vendored
Normal file
11
vendor/uduncloud/udun-wallet-sdk/src/UdunDispatchException.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Udun\Dispatch;
|
||||
class UdunDispatchException extends \Exception
|
||||
{
|
||||
public function __construct($code,$msg){
|
||||
var_dump("code:".$code);
|
||||
var_dump("msg:".$msg);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user