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

163 lines
4.2 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 51云冲服务 http://8.136.206.133
* Class Common
* @package app\channel\service
*/
class Yunchong extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'phone_no',
'cash' => 'amount',
);
$this->api = 'api/order/phone';
return $this->submit($param, $check);
}
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'card_id',
'cash' => 'amount',
);
$this->api = 'api/order/oil';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'card_id',
'cash' => 'amount',
);
$this->api = 'api/order/oil';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['md5']);
unset($request['s_order']);
/*
$sign = strtoupper($this->_sign($request));
if ($sign != $data['md5']) {
return false;
}
*/
$result = array();
$result['cash'] = 1;
if ($data['status'] == 'SUCCESS') {
$result['status'] = 2;
} elseif ($data['status'] == 'FAIL') {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['operatorId']) && $data['operatorId'] && $data['operatorId'] != 'NONE') {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['operatorId'];
}
$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'] == '0') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['msg']) ? $array['msg'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询接口
public function query($param)
{
}
# 提交数据
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['username'] = $this->mid;
$request['out_order_id'] = $param['order'];
$request['notify_url'] = $this->getNotify($param['order'], 1);
$request['md5'] = strtoupper($this->_sign($request));
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
if (isset($response['array']['result']['order_id'])) {
$channel_order_id = $response['array']['result']['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)
{
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
if (isset($request[$k]) && $request[$k]) {
$signature_string .= $k . '' . $request[$k];
}
}
$signature_string .= $this->token;
return md5($signature_string);
}
}