REAPI/app/channel/service/system/Huashang.php
2024-09-29 15:43:18 +08:00

149 lines
4.0 KiB
PHP

<?php
namespace app\channel\service\system;
/**
*
* Class Bodingcheng
* @package app\channel\service
*/
class Huashang extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = '';
public function dhcz($param)
{
$check = array
(
'mobile' => 'phoneNo',
'cash' => 'amount',
'operator' => 'operator',
);
$param['operator'] = 'MOB';
if (isset($param['isp']) && $param['isp']) {
if ($param['isp'] == 1) {
$param['operator'] = 'MOB';
} elseif ($param['isp'] == 2) {
$param['operator'] = 'UNI';
} elseif ($param['isp'] == 3) {
$param['operator'] = 'TEL';
}
}
$this->api = '/api/gateway/v4/recharge/provider';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
if ($data['status'] == 'PAID_SUCCESS') {
$result['status'] = 2;
} elseif ($data['status'] == 'FAIL_INVALID' || $data['status'] == 'FAIL_VERIFY') {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['orderId']) && $data['orderId'] && $data['orderId'] != '*') {
$data['s_nubmer'] = $result['s_nubmer'] = $data['orderId'];
}
$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'] == '1') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = $data;
}
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['expireAt'] = 86400;
$request['ssid'] = $this->mid;
//$request['ProductCode'] = $this->getGid($param['cash']);
$request['rechargeNo'] = $param['order'];
$request['timestamp'] = $this->msectime();
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request);
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request, true);
$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 _sign($request)
{
ksort($request);
$signature_string = '';
foreach ($request as $k => $v) {
$signature_string .= $k . '=' . $v . '&';
}
$signature_string = substr($signature_string, 0, -1);
$signature_string .= $this->token;
print_r($signature_string);
return md5($signature_string);
}
private function msectime()
{
list($s1, $s2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
}
}