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

168 lines
4.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 Jinyu extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $type = 4;
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'account',
'cash' => 'amount',
'apiProduct' => 'apiProduct',
);
$param['apiProduct'] = 'dhcz';
return $this->submit($param, $check);
}
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'account',
'cash' => 'amount',
'apiProduct' => 'apiProduct',
);
$param['apiProduct'] = 'zsycz';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'account',
'cash' => 'amount',
'apiProduct' => 'apiProduct',
);
$param['apiProduct'] = 'zshcz';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
if ($data['status'] == 'success') {
$result['status'] = 2;
} elseif ($data['status'] == 'failed') {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['operatorTradeNo']) && $data['operatorTradeNo']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['operatorTradeNo'];
}
$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['returnCode']) && $array['returnCode'] == '200' && isset($array['data']['status']) && $array['data']['status'] == 'waiting') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['returnMessage']) ? $array['returnMessage'] : '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'];
$request['secretId'] = $this->mid;
$request['outTradeNo'] = $param['order'];
//$request['packageCode'] = $this->getCode($param['cash']);
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/v1/rest/multi/charge/common';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
if (isset($response['array']['inTradeNo'])) {
$channel_order_id = $response['array']['inTradeNo'];
}
$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 == 30) {
return 10365;
} elseif ($cash == 50) {
return 10366;
} elseif ($cash == 100) {
return 10367;
} elseif ($cash == 200) {
return 10368;
}
return 0000;
}
private function _sign($request)
{
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
$signature_string .= $k . '=' . $v . '&';
}
$signature_string .= 'secretKey=' . $this->token;
return md5($signature_string);
}
}