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

147 lines
3.7 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 Weizhixing extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
protected $apitype = 1;
protected $sign = array();
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'cardNo',
'cash' => 'amount',
'cardType' => 'cardType',
);
$param['cardType'] = 'SH';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zsycz($param)
{
$check = array
(
'card' => 'cardNo',
'cash' => 'amount',
'cardType' => 'cardType',
);
$param['cardType'] = 'SY';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$sign = $this->_sign($request);
if ($sign != $data['sign']) {
//return false;
}
$result = array();
$result['cash'] = 1;
if ($data['status'] == 1) {
$result['status'] = 2;
} elseif ($data['status'] == 0) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
$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['status']) && $array['status'] == '1') {
# 正确
$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;
}
$this->api = 'api/v3.0/server/order/charge';
$request = $param['detail'];
$temp = explode('|', $this->mid);
$request['appKey'] = $temp[0];
$request['accountCode'] = $temp[1];
$request['transNo'] = $param['order'];
$request['timeStamp'] = time();
$request['sign'] = $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']['order_no'])) {
$channel_order_id = $response['array']['order_no'];
}
$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) {
$signature_string .= $k . '=' . $v . '&';
}
$signature_string .= 'key=' . $this->token;
return strtoupper(md5($signature_string));
}
}