192 lines
5.1 KiB
PHP
192 lines
5.1 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 服务
|
||
|
* Class Tiancheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Baoreapi extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $method = '';
|
||
|
|
||
|
|
||
|
# 电话充值 拼音来吧
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'mobile',
|
||
|
'cash' => 'cash',
|
||
|
'api_product' => 'api_product',
|
||
|
);
|
||
|
$param['api_product'] = 'dhcz';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石油油卡充值 拼音来吧
|
||
|
public function zsycz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'card',
|
||
|
'cash' => 'cash',
|
||
|
//'idCard' => 'idCard',
|
||
|
//'realName' => 'realName',
|
||
|
'api_product' => 'api_product',
|
||
|
);
|
||
|
$param['api_product'] = 'zsycz';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function zshcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'card',
|
||
|
'cash' => 'cash',
|
||
|
'api_product' => 'api_product',
|
||
|
);
|
||
|
$param['api_product'] = 'zshcz_tc';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值透传
|
||
|
public function zshcz_tc($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'card',
|
||
|
'cash' => 'cash',
|
||
|
'api_product' => 'api_product',
|
||
|
);
|
||
|
$param['api_product'] = 'zshcz_tc';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
unset($request['signature']);
|
||
|
// $request = $this->getParam($request, $this->token, 2);
|
||
|
// if ($request['signature'] != $data['signature']) {
|
||
|
// return false;
|
||
|
// }
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['status'] == 2) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['status'] == 3) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
if (isset($this->data['product_key']) && strstr($this->data['product_key'], '_tc') && isset($data['vnum']) && $data['vnum']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['vnum'];
|
||
|
}
|
||
|
*/
|
||
|
if (isset($data['s_nubmer']) && $data['s_nubmer']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['s_nubmer'];
|
||
|
}
|
||
|
|
||
|
if (isset($data['msg']) && $data['msg']) {
|
||
|
# 错误信息
|
||
|
$data['msg'] = $result['msg'] = $data['msg'];
|
||
|
}
|
||
|
|
||
|
// $result['data'] = $data;
|
||
|
$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['info']) ? $array['info'] : 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 查询接口
|
||
|
public function query($param)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
# 查询余额接口
|
||
|
public function account($day)
|
||
|
{
|
||
|
$request['day'] = $day;
|
||
|
$request['appid'] = $this->mid;
|
||
|
$request['api_product'] = 'query';
|
||
|
$request = $this->getParam($request, $this->token, 2);
|
||
|
$url = $this->host . 'gateway/api.handle/accountByDay';
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
|
||
|
return $response['array']['data'];
|
||
|
}
|
||
|
|
||
|
# 提交数据
|
||
|
private function submit($param, $check)
|
||
|
{
|
||
|
$param = $this->param($param, $check);
|
||
|
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
|
return $param;
|
||
|
}
|
||
|
|
||
|
return $this->send($param);
|
||
|
}
|
||
|
|
||
|
private function send($param, $parent_order = '')
|
||
|
{
|
||
|
$request = $param['detail'];
|
||
|
$request['appid'] = $this->mid;
|
||
|
$request['order'] = $param['order'];
|
||
|
$request['notify'] = $this->getNotify($param['order'], 1);
|
||
|
$request = $this->getParam($request, $this->token, 2);
|
||
|
$url = $this->host . 'gateway/api.handle/submit';
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
//$response['data'] = '{}';
|
||
|
//$response['msg'] = 'ok';
|
||
|
$channel_order_id = '';
|
||
|
|
||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'], $parent_order);
|
||
|
|
||
|
return $response['msg'];
|
||
|
}
|
||
|
}
|