195 lines
5.3 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 服务
* Class Bodingcheng
* @package app\channel\service
*/
class Juhe extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
protected $sign = array();
# 手机充值
//你们需要话费凭证的话就在回调里加上operator_order_no 这个参数
public function dhcz($param)
{
$check = array
(
'mobile' => 'phoneno',
'cash' => 'cardnum',
);
$this->api = 'ofpay/mobile/onlineorder';
$this->sign = array('key', 'phoneno', 'cardnum', 'orderid');
return $this->submit($param, $check);
}
# 中石油充值
public function zsycz($param)
{
return $this->zshcz($param, 2);
}
# 中石化油卡充值
public function zshcz($param, $type = 1)
{
$check = array
(
'card' => 'game_userid',
'cash' => 'proid',
'cardnum' => 'cardnum',
'chargeType' => 'chargeType',
);
$param['cardnum'] = 1;
$param['chargeType'] = $type;
$this->api = 'ofpay/sinopec/onlineorder';
$this->sign = array('key', 'proid', 'cardnum', 'game_userid', 'orderid');
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$sign = $this->_sign($request, array('sporder_id', 'orderid'), 2);
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['sta'] == 1) {
$result['status'] = 2;
} elseif ($data['sta'] == 9) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['gascard_code']) && $data['gascard_code']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['gascard_code'];
}
if (isset($data['rec_msg']) && $data['rec_msg']) {
$data['rec_msg'] = urldecode($data['rec_msg']);
}
if (isset($data['err_msg']) && $data['err_msg']) {
$data['err_msg'] = urldecode($data['err_msg']);
}
$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($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'];
if ($request['chargeType'] == 2) {
$request['proid'] = 10008;
} else {
$request['proid'] = $this->getCode($param['cash']);
if (!$request['proid']) {
return 'order';
}
}
$request['key'] = $this->mid;
$request['orderid'] = $param['order'];
$request['gasCardTel'] = '18900000000';
$request['returnurl'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request, $this->sign, 1);
$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']['sporder_id'])) {
$channel_order_id = $response['array']['result']['sporder_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 ($cash == 50) {
return 10000;
} elseif ($cash == 100) {
return 10001;
} elseif ($cash == 200) {
return 10002;
} elseif ($cash == 500) {
return 10003;
} elseif ($cash == 1000) {
return 10004;
}
return false;
}
private function _sign($request, $param, $type = 1)
{
if ($type == 1) {
$signature_string = $this->token;
} else {
$signature_string = $this->mid;
}
foreach ($param as $k => $v) {
if (isset($request[$v]) && $request[$v]) {
$signature_string .= $request[$v];
}
}
return md5($signature_string);
}
}