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

163 lines
4.3 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 服务
* Class Tiancheng
* @package app\channel\service
*/
class Jinyuanbo extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = '';
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'cz_account',
'cash' => 'mianzhi_amount',
);
return $this->submit($param, $check);
}
# 手机充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'cz_account',
'cash' => 'mianzhi_amount',
'yys_code' => 'yys_code',
);
$param['yys_code'] = 'telecom';
if (isset($param['isp']) && $param['isp']) {
if ($param['isp'] == 1) {
$param['yys_code'] = 'mobile';
} elseif ($param['isp'] == 2) {
$param['yys_code'] = 'unicom';
} elseif ($param['isp'] == 3) {
$param['yys_code'] = 'telecom';
}
}
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
if ($data['code'] == '0000') {
$result['status'] = 2;
} else {
$result['status'] = 3;
}
if (isset($data['pz_order_id']) && $data['pz_order_id']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['pz_order_id'];
}
$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'] == '200') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['message']) ? $array['message'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $array,
'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'];
$temp = explode('|', $this->mid);
$request['partner_id'] = $temp[0];
$request['mer_trade_no'] = $param['order'];
$request['charset'] = 'UTF-8';
$request['sign_type'] = 'MD5';
if (!isset($temp[1])) {
$temp[1] = 'hfhcmc';
}
$request['channel_type'] = $temp[1];
$request['timestamp'] = date('Y-m-d H:i:s');
if (!isset($temp[2])) {
$temp[2] = '00';
}
$request['province_code'] = $temp[2];
$request['notify_url'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request);
$url = $this->host . 'order/createOrder';
$response = $this->curl('post', $url, $request, true);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['data']['plat_order_id'])) {
$channel_order_id = $response['array']['data']['plat_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 _sign($request)
{
unset($request['yys_code']);
unset($request['province_code']);
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
if ($v) {
//$v = urlencode($v);
$signature_string .= $k . $v;
}
}
$signature_string .= 'key' . $this->token;
return md5($signature_string);
}
}