REAPI/app/channel/service/system/Douyinnew.php

147 lines
4.2 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
use app\merchant\service\OrderService;
use app\merchant\service\MerchantService;
/**
* 服务
* Class Tiancheng
* @package app\channel\service
*/
class Douyinnew extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = '';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'account_id',
'cash' => 'quota',
);
$this->api = 'subCharge';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
$result['status'] = $data['status'];
$result['yes'] = 'SUCCESS';
$result['data'] = $data;
return $result;
}
# 数据响应格式处理
public function response($data)
{
$log['type'] = 'response';
$log['data'] = $data;
$log['config'] = $this->data;
$this->log($log);
$array = $this->json_decode($data);
if (!$array) {
$msg = 'error';
} elseif (isset($array['code']) && $array['code'] == '1') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['message']) ? $array['message'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询接口
public function query($order)
{
$request['member_id'] = $this->mid;
$request['order_id'] = $order['order_id'];
$request['sign'] = $this->_qsign($request);
$url = $this->host . 'Chargingorder';
$response = $this->curl('post', $url, $request, true);
$log['type'] = 'query_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
if (strstr($response, '{')) {
$array = $this->json_decode($response);
} else {
$array = array();
}
$result = array();
$result['status'] = 4;
if (isset($array['msg']['used_quota']) && isset($array['msg']['quota']) && $array['msg']['quota'] == $array['msg']['used_quota']) {
$result['status'] = 2;
} else {
if ($order['create_at']) {
$time = $this->maketime($order['create_at']);
$cur = time() - $time;
if ($cur > 930) {
$result['status'] = 3;
}
}
}
return $result;
}
# 提交数据
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
$request['id'] = $this->mid;
$request['sign'] = $this->_sign($request);
$send = $param['detail'];
//$request['param'] = 'adder='.$this->mid.'&way=808&account_id='.$send['account_id'].'&quota='.$send['quota'].'&expire_time='.date('Ymd').'&remark='.$param['order'].'&param1=1&param2=2&param3=3&param4=4&param5=5';
$request['param'] = 'adder='.$this->mid.'&way=808&account_id='.$send['account_id'].'&quota='.$send['quota'].'&expire_time=900&remark='.$param['order'].'&param1=1&param2=2&param3=3&param4=4&param5=5';
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
$channel_order_id = '';
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
private function _sign($request)
{
$signature_string = 'key='.$this->token.'&id=' . $request['id'];
return md5($signature_string);
}
private function _qsign($request)
{
$signature_string = 'member_id='.$request['member_id'] . '&order_id='.$request['order_id'].'&key=' . $this->token;
return md5($signature_string);
}
}