215 lines
5.8 KiB
PHP
215 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 服务
|
|
* Class Bodingcheng
|
|
* @package app\channel\service
|
|
*/
|
|
class Guorui extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'host';
|
|
protected $mid = 'mid';
|
|
protected $token = 'token';
|
|
protected $api = 'api';
|
|
|
|
# 手机充值
|
|
public function dhcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'account',
|
|
'cash' => 'amount',
|
|
'buy_type' => 'buy_type',
|
|
'cat_id' => 'cat_id',
|
|
);
|
|
$param['buy_type'] = 1;
|
|
$param['cat_id'] = 1;
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
if ($param['isp'] == 1) {
|
|
$param['cat_id'] = 1;
|
|
} elseif ($param['isp'] == 2) {
|
|
$param['cat_id'] = 2;
|
|
} elseif ($param['isp'] == 3) {
|
|
$param['cat_id'] = 3;
|
|
}
|
|
}
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石油充值
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'account',
|
|
'cash' => 'amount',
|
|
'buy_type' => 'buy_type',
|
|
'cat_id' => 'cat_id',
|
|
);
|
|
$param['buy_type'] = 4;
|
|
$param['cat_id'] = 4;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'account',
|
|
'cash' => 'amount',
|
|
'buy_type' => 'buy_type',
|
|
'cat_id' => 'cat_id',
|
|
);
|
|
$param['buy_type'] = 4;
|
|
$param['cat_id'] = 5;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
unset($request['sign']);
|
|
unset($request['s_order']);
|
|
$sign = $this->_sign($request, array('userid', 'order_id', 'account', 'amount', 'price', 'state', 'user_order'));
|
|
if ($sign != $data['sign']) {
|
|
return false;
|
|
}
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['state'] == 'success') {
|
|
$result['status'] = 2;
|
|
} elseif ($data['state'] == 'failed') {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 4;
|
|
}
|
|
|
|
if (isset($data['voucher']) && $data['voucher']) {
|
|
# 流水号
|
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['voucher'];
|
|
}
|
|
|
|
$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'] == '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;
|
|
}
|
|
$this->api = 'recharge/buy.do';
|
|
$request = $param['detail'];
|
|
$request['userid'] = $this->mid;
|
|
$request['user_order'] = $param['order'];
|
|
//$request['notify_url'] = $this->getNotify($param['order'], 1);
|
|
$request['create_time'] = date('YmdHis');
|
|
$request['product_id'] = $this->getCode($param['cash'], $request['cat_id']);
|
|
if (!$request['product_id']) {
|
|
return 'order';
|
|
}
|
|
$request['sign'] = $this->_sign($request, array('userid', 'user_order', 'create_time', 'buy_type', 'account', 'product_id', 'amount'));
|
|
$url = $this->host . $this->api;
|
|
|
|
$response = $this->curl('get', $url, $request);
|
|
$response = $this->response($response);
|
|
//$response['data'] = '';
|
|
//$response['msg'] = 'ok';
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['order_id']) && $response['array']['order_id']) {
|
|
$channel_order_id = $response['array']['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 getCode($cash, $type)
|
|
{
|
|
if ($type == 2) {
|
|
if ($cash == 20) {
|
|
return 20051;
|
|
} elseif ($cash == 30) {
|
|
return 20052;
|
|
} elseif ($cash == 50) {
|
|
return 20053;
|
|
} elseif ($cash == 100) {
|
|
return 20054;
|
|
}
|
|
}
|
|
if ($type == 1) {
|
|
if ($cash == 50) {
|
|
return 20034;
|
|
} elseif ($cash == 100) {
|
|
return 20035;
|
|
} elseif ($cash == 200) {
|
|
return 20036;
|
|
} elseif ($cash == 300) {
|
|
return 20037;
|
|
} elseif ($cash == 500) {
|
|
return 20038;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private function _sign($request, $param)
|
|
{
|
|
ksort($request);
|
|
$signature_string = '';
|
|
foreach ($request as $k => $v) {
|
|
if (in_array($k, $param)) {
|
|
$signature_string .= $v;
|
|
}
|
|
}
|
|
|
|
$signature_string .= $this->token;
|
|
return strtoupper(md5($signature_string));
|
|
}
|
|
} |