You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
5.6 KiB
149 lines
5.6 KiB
3 months ago
|
<?php
|
||
|
|
||
|
namespace app\home\service;
|
||
|
|
||
|
use app\model\RechargeApplyModel;
|
||
|
use app\model\StockMarketModel;
|
||
|
use app\model\UserWithdrawalModel;
|
||
|
use think\facade\Log;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 处理团队佣金业务
|
||
|
*/
|
||
|
class StarPayService extends BaseHomeService
|
||
|
{
|
||
|
public $sign_key="301430b998cb571008f21302adbd4589";
|
||
|
public $merchant_no="071670";
|
||
|
public $pay_url="https://api.star-pay.vip/api/gateway/pay";
|
||
|
|
||
|
public function create_order($orderId, $amount,$product,$fiat_currency='')
|
||
|
{
|
||
|
$post_data['merchant_no'] = $this->merchant_no;
|
||
|
$post_data['timestamp'] = time();
|
||
|
$post_data['sign_type'] = 'MD5';
|
||
|
|
||
|
$params['merchant_ref']=$orderId;
|
||
|
$params['product']=$product;
|
||
|
$params['amount']=$amount;
|
||
|
$params['extra']=(object) [];
|
||
|
if($product=='TRC20Buy'){
|
||
|
$params['extra']->fiat_currency=$fiat_currency;
|
||
|
}
|
||
|
$post_data['params'] = json_encode($params);
|
||
|
|
||
|
|
||
|
$post_data['sign'] =$this->sign_data($post_data);
|
||
|
|
||
|
Log::info('starPay post-: ' . json_encode($post_data));
|
||
|
$header = array("Content-Type:application/x-www-form-urlencoded");
|
||
|
$res=$this->curlPost($this->pay_url,$post_data,10,$header);
|
||
|
Log::info('starPay 返回-: ' . $res);
|
||
|
$result=json_decode($res,true);
|
||
|
return $result;
|
||
|
}
|
||
|
public function starPayNotify($data){
|
||
|
Log::info('收到star_pay异步回调:'.json_encode($data));
|
||
|
$sign=$this->sign_data($data);
|
||
|
if($sign==$data['sign']){
|
||
|
Log::info('star_pay签名校验成功:'.json_encode($data));
|
||
|
$result=json_decode($data['params'],true);
|
||
|
if($result['status']==1){
|
||
|
$order_info=RechargeApplyModel::getOrderByNo([
|
||
|
'order_no'=>$result['merchant_ref']
|
||
|
]);
|
||
|
if($order_info && $result['amount']==$order_info['total_amount']){
|
||
|
if($order_info['status']==0){
|
||
|
return (new PayService())->dealPayNotify($order_info);
|
||
|
}
|
||
|
}else{
|
||
|
Log::info('star_pay支付订单不存在:'.json_encode($data));
|
||
|
}
|
||
|
}else{
|
||
|
Log::info('star_pay支付订单支付失败:'.json_encode($data));
|
||
|
}
|
||
|
}else{
|
||
|
Log::info('star_pay签名校验失败:'.json_encode($data));
|
||
|
}
|
||
|
return [
|
||
|
'code'=>300,
|
||
|
'msg'=>'FAIL'
|
||
|
];
|
||
|
|
||
|
}
|
||
|
private function sign_data($post_data){
|
||
|
if(is_array($post_data['params'])){
|
||
|
$sign_str=$this->merchant_no.json_encode($post_data['params']).$post_data['sign_type'].$post_data['timestamp'].$this->sign_key;
|
||
|
}else{
|
||
|
$sign_str=$this->merchant_no.$post_data['params'].$post_data['sign_type'].$post_data['timestamp'].$this->sign_key;
|
||
|
}
|
||
|
|
||
|
Log::info('star_pay签名:'.json_encode($sign_str));
|
||
|
return md5($sign_str);
|
||
|
}
|
||
|
public function getTRC20BuyList()
|
||
|
{
|
||
|
$gpx_rate=StockMarketModel::where('stock_market_type',14)->value('rate');
|
||
|
$eur_rate=StockMarketModel::where('stock_market_type',15)->value('rate');
|
||
|
$json=[
|
||
|
[
|
||
|
"bank_name"=>"GBP",
|
||
|
"bank_code"=> "GBP",
|
||
|
"exchange_rate"=>$gpx_rate/100,
|
||
|
"unit"=>'GBP',
|
||
|
"min_num"=>10,
|
||
|
"max_num"=>30000,
|
||
|
],
|
||
|
[
|
||
|
"bank_name"=> "USD",
|
||
|
"bank_code"=> "USD",
|
||
|
"exchange_rate"=>1,
|
||
|
"unit"=>'USD',
|
||
|
"min_num"=>10,
|
||
|
"max_num"=>100000,
|
||
|
],
|
||
|
[
|
||
|
"bank_name"=> "EUR",
|
||
|
"bank_code"=> "EUR",
|
||
|
"exchange_rate"=>$eur_rate,
|
||
|
"unit"=>'EUR',
|
||
|
"min_num"=>10,
|
||
|
"max_num"=>92945,
|
||
|
],
|
||
|
];
|
||
|
return $this->toData('0', 'SUCCESS', $json);
|
||
|
}
|
||
|
private function curlPost($url, $post_data = array(), $timeout = 5, $header = "", $data_type = "")
|
||
|
{
|
||
|
$header = empty($header) ? '' : $header;
|
||
|
//支持json数据数据提交
|
||
|
if ($data_type == 'json') {
|
||
|
$post_string = json_encode($post_data);
|
||
|
} elseif ($data_type == 'array') {
|
||
|
$post_string = $post_data;
|
||
|
} elseif (is_array($post_data)) {
|
||
|
$post_string = http_build_query($post_data, '', '&');
|
||
|
}
|
||
|
|
||
|
$ch = curl_init(); // 启动一个CURL会话
|
||
|
curl_setopt($ch, CURLOPT_URL, $url); // 要访问的地址
|
||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 // https请求 不验证证书和hosts
|
||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
|
||
|
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
|
||
|
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
|
||
|
//curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
|
||
|
curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求
|
||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包
|
||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置超时限制防止死循环
|
||
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||
|
//curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
|
||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
|
||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头
|
||
|
$result = curl_exec($ch);
|
||
|
curl_close($ch);
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|