251 lines
7.1 KiB
PHP
Raw Permalink Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 雨瑞服务
* Class Bodingcheng
* @package app\channel\service
*/
class Rainend extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api/supplier/submit';
protected $deskey = 'deskey';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'account_no',
'cash' => 'amount',
'order_type' => 'order_type',
);
$param['order_type'] = 'dy';
return $this->submit($param, $check);
}
# 抖音充值
public function dy($param)
{
$check = array
(
'account' => 'account',
'num' => 'num',
);
$this->api = 'api/order/place';
return $this->submit($param, $check);
}
# 快手充值
public function ks($param)
{
$check = array
(
'account' => 'account',
'num' => 'num',
);
$this->api = 'api/order/place';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
// $sign = $this->_sign($request, array('account_no', 'amount', 'out_order_no', 'order_type', 'pay_status', 'notify_url'));
// if ($sign != $request['sign']) {
// return false;
// }
$result = array();
$result['cash'] = 1;
if ($request['useState'] == 1) {
$result['status'] = 2;
} elseif ($request['useState'] == 2) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($request['remark']) && $request['remark'] ) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $request['remark'];
}
$result['yes'] = '{"success"}';
// var_dump($result);die;
$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'] == '0' || $array['code'] == '2') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['msg']) ? $array['msg'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询接口
public function query($order)
{
$orderRequest = json_decode($order['request'], true);
$request['appid'] = $this->mid;
// $request['orderid'] = $order['order_id'];
$request['timestamp'] =time();
$request['outorderid'] = $order['order_id'];
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/order/query';
$response = $this->curl('get', $url, $request);
$log['type'] = 'query_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
$array = $this->json_decode($response);
#{"Code":1,"Content":{"Cards":[],"SaleMoney":"10.2200","StatusMsg":"成功","Status":"1","UserOrderId":"3851936066457190837","OrderId":"13006988870623232"},"Message":"响应成功"}
$result['status'] = 4;
if (isset($array['code']) && $array['code'] = 0) {
if($array['state'] == 1){
$result['useState'] = 1;
$result['status'] = 2;
}elseif ($array['state'] == 2){
$result['useState'] = 2;
$result['status'] = 3;
}
if (isset($array['remark']) && $array['remark']) {
# 流水号
// $data['szRtnMsg']
$result['remark'] = $array['remark'];
}
}
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 = $param['detail'];
$request['appid'] = $this->mid;
$request['timestamp'] = time();
$request['productid'] = $this->getGid($param['cash']);
$request['account'] = $this->encryptData($request['account']);
$request['num'] = $request['num']*$param['cash'];
$request['expirationseconds'] = '3600';
$request['outorderid'] = $param['order'];
$request['callbackurl'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request);
// var_dump($request);die;
$url = $this->host . $this->api;
// $response = $this->curl('post', $url, $request);
$response =http_post($url,$request);
$response = $this->response($response);
// var_dump($response);die;
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
if (isset($response['array']['orderId'])) {
$channel_order_id = $response['array']['orderId'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
public function encryptData($input)
{
// $cipher = "DES-ECB";
// $encrypted = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv);
// $ivlen = openssl_cipher_iv_length('DES-ECB'); // 获取密码iv长度
// if ($ivlen > 0) {
// $iv = openssl_random_pseudo_bytes($ivlen);
// } else {
// $iv = '';
// }
// $json = $this->channel['describe'];
// $array = $this->json_decode($json);
// if(isset($array['deskey'])){
// $this->deskey = $array['deskey'];
$substr = mb_substr($this->token, 0, 8);
$data = [
'data'=>$input,
'token'=>$substr
];
$data = http_post('http://101.43.58.121:9011/', $data);
// }
// $data = openssl_encrypt($input, 'des-ede-ecb', $substr ,OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);
// $errors = openssl_get_cipher_methods();
//// var_dump(base64_encode($data));die;
//
// var_dump($data);die;// 加密die;
return $data;
}
private function _sign($request)
{
// ksort($param);
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
$signature_string .= $k . '=' . $v ;
}
$signature_string = strtolower($signature_string);
// $signature_string = substr($signature_string, 0, -1);
$signature_string .= $this->token;
// var_dump($signature_string);die;
return md5($signature_string);
}
}