123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services;
- use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
- use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
- use Darabonba\OpenApi\Models\Config;
- use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
- use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
- use Udun\Dispatch\UdunDispatch;
- /**
- * udun钱包服务管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class UdunpayService
- * @package App\Services
- */
- class UdunpayService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- protected $dispatch = null;
- protected static $config = [];
- public function __construct()
- {
- $config = ConfigService::make()->getConfigByGroup(10);
- self::$config = [
- 'merchant_no' => isset($config['udun_merchant_no']['value'])? $config['udun_merchant_no']['value'] : '', //商户号
- 'api_key' => isset($config['udun_api_key']['value'])? $config['udun_api_key']['value'] : '', //apikey
- 'gateway_address' => isset($config['udun_gateway_address']['value'])? $config['udun_gateway_address']['value'] : '', //节点
- 'callUrl'=> url('/notify/wallet/udunpay','',true), //回调地址
- 'debug' => false //调试模式
- ];
- $this->dispatch = new UdunDispatch(self::$config);
- }
- /**
- * 静态入口
- * @return UdunpayService|static|null
- */
- public static function make(){
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 获取支持的币种
- * @param bool $showBalance 是否返回余额
- * @return mixed
- */
- public function supportCoins($showBalance=true)
- {
- return $this->dispatch->supportCoins($showBalance);
- }
- /**
- * 创建钱包地址
- * @param string $mainCoinType
- * @return mixed
- */
- public function createAddress($mainCoinType='195')
- {
- $result = $this->dispatch->createAddress($mainCoinType);
- $code = isset($result['code'])? intval($result['code']) : 0;
- $address = isset($result['data']['address'])? trim($result['data']['address']) : '';
- if($code == 200 && $address){
- return $address;
- }else{
- RedisService::set("caches:udunpay:createAddress:error_".date('YmdHis'),['mainCoinType'=>$mainCoinType,'result'=> $result], 7200);
- return '';
- }
- }
- /**
- * 验证钱包地址合法性
- * @param $address 地址
- * @param string $mainCoinType 主币
- * @return mixed
- */
- public function checkAddress($address,$mainCoinType='195')
- {
- return $this->dispatch->checkAddress($mainCoinType,$address);
- }
- /**
- * 查询地址是否存在
- * @return mixed
- */
- public function existAddress($address,$mainCoinType='195')
- {
- return $this->dispatch->existAddress($mainCoinType,$address);
- }
- /**
- * 提币
- * @return mixed
- */
- public function withdraw($address, $amount, $orderNo, $mainCoinType='195', $coinType='', $remark='')
- {
- $coinType = $coinType? $coinType : 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t';
- return $this->dispatch->withdraw($orderNo,$mainCoinType,$coinType,$address,$amount,$remark);
- }
- /**
- * 回调
- * @return mixed
- */
- public function callback()
- {
- $result = $this->dispatch->callback();
- RedisService::set("caches:udunpay:notify",['params'=> request()->all(),'result'=> $result], 3600);
- return $result;
- }
- /**
- * 回调处理
- * @param $params
- */
- public function catchNotify($params)
- {
- RedisService::set('caches:udunpay:notify',$params);
- }
- }
|