183 lines
4.8 KiB
PHP
183 lines
4.8 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 中垒服务
|
||
|
* Class Bodingcheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Zhonglei extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
|
||
|
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function zshcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'recharge_account',
|
||
|
// 'merchant_order_id' => 'order_id',
|
||
|
);
|
||
|
|
||
|
// $this->apitype = 2;
|
||
|
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
$result['status'] = 4;
|
||
|
if(isset($data['query_status'])){
|
||
|
if ($data['query_status'] == 1) {
|
||
|
$result['status'] = 2;
|
||
|
} else if($data['query_status'] == 9) {
|
||
|
$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['error_code']) && $array['error_code'] == '0') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['reason']) ? $array['reason'] : 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 查询接口
|
||
|
public function query($order)
|
||
|
{
|
||
|
$request['key'] = $this->token;
|
||
|
$request['order_id'] = $order['merchant_order_id'];
|
||
|
$request['timestamp'] = time();
|
||
|
$request['sign'] = strtolower(md5($this->mid.$this->token.$request['order_id'].$request['timestamp'] ));
|
||
|
$url = $this->host . 'yk/apply/order_query_sign';
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
|
||
|
$log['type'] = 'query_response';
|
||
|
$log['data'] = $response;
|
||
|
$log['config'] = $this->data;
|
||
|
$this->log($log);
|
||
|
|
||
|
$array = $this->json_decode($response,true);
|
||
|
|
||
|
$result = array();
|
||
|
$result['status'] = 4;
|
||
|
if ($array['error_code']==1&&isset($array['result']) ) {
|
||
|
if($array['status'] == 1){
|
||
|
$result['query_status'] = 1;
|
||
|
|
||
|
$result['status'] = 2;
|
||
|
}elseif ($array['status'] == 9){
|
||
|
$result['query_status'] = 9;
|
||
|
$result['status'] = 3;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
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['num']=1;
|
||
|
if(!in_array($request['pid'],[10007,10008])){
|
||
|
$request['num']=$request['cash'];
|
||
|
}
|
||
|
// if (empty($request['phone'])) {
|
||
|
// $request['phone'] = $this->getMobile($request['cardNo'], 1);
|
||
|
// }
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
|
||
|
$this->api = 'yk/apply/sub';
|
||
|
$url = $this->host . $this->api;
|
||
|
|
||
|
$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']);
|
||
|
return $response['msg'];
|
||
|
}
|
||
|
|
||
|
private function getCode($cash)
|
||
|
{
|
||
|
if ($this->apitype == 1) {
|
||
|
if ($cash == 20) {
|
||
|
return 20051;
|
||
|
} elseif ($cash == 30) {
|
||
|
return 20052;
|
||
|
} elseif ($cash == 50) {
|
||
|
return 20053;
|
||
|
} elseif ($cash == 100) {
|
||
|
return 20054;
|
||
|
}
|
||
|
} elseif ($this->apitype == 2) {
|
||
|
if ($cash == 20) {
|
||
|
return 20051;
|
||
|
} elseif ($cash == 30) {
|
||
|
return 20052;
|
||
|
} elseif ($cash == 50) {
|
||
|
return 20053;
|
||
|
} elseif ($cash == 100) {
|
||
|
return 20054;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
private function _sign($request)
|
||
|
{
|
||
|
$str=strtolower(md5($this->mid.$this->token.$request['pid'].$request['num'].$request['recharge_acctount'].$request['order_id']));
|
||
|
return $str;
|
||
|
}
|
||
|
}
|