212 lines
5.9 KiB
PHP
212 lines
5.9 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 服务
|
||
|
* Class Bodingcheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Haixinnew extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'order/submit';
|
||
|
protected $teltype = -1;
|
||
|
|
||
|
# 手机充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'number',
|
||
|
'cash' => 'faceValue',
|
||
|
);
|
||
|
$this->teltype = 1;
|
||
|
if (isset($param['isp']) && $param['isp']) {
|
||
|
$this->teltype = $param['isp'];
|
||
|
}
|
||
|
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
unset($request['sign']);
|
||
|
unset($request['s_order']);
|
||
|
$sign = $this->_sign($request, array('userId', 'key', 'code', 'orderId', 'requestId'));
|
||
|
if ($sign != $data['sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['code'] == '200') {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['code'] == '505') {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
|
||
|
if (isset($data['certificate']) && $data['certificate']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['certificate'];
|
||
|
}
|
||
|
|
||
|
$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['msg']) ? $array['msg'] : '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 (isset($request['checkPrice'])) {
|
||
|
$request['checkPrice'] = round($request['checkPrice'] * $this->product['percent'], 4);
|
||
|
}*/
|
||
|
$request['requestId'] = $param['order'];
|
||
|
$request['callbackUrl'] = $this->getNotify($param['order'], 1);
|
||
|
$request['productId'] = $this->getCode($param['cash']);
|
||
|
if (!$request['productId']) {
|
||
|
return 'order';
|
||
|
}
|
||
|
$request['sign'] = $this->_sign($request, array('userId', 'key', 'productId', 'requestId', 'number'));
|
||
|
$url = $this->host . $this->api;
|
||
|
|
||
|
$header['Authorization-User'] = $this->mid;
|
||
|
$response = $this->curl('post', $url, $request, true, $header);
|
||
|
$response = $this->response($response);
|
||
|
//$response['data'] = '';
|
||
|
//$response['msg'] = 'ok';
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['data']['orderId']) && $response['array']['data']['orderId']) {
|
||
|
$channel_order_id = $response['array']['data']['orderId'];
|
||
|
}
|
||
|
|
||
|
$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->teltype > 0) {
|
||
|
if ($this->teltype == 1) {
|
||
|
if ($cash == 10) {
|
||
|
return 10559;
|
||
|
} elseif ($cash == 20) {
|
||
|
return 10560;
|
||
|
} elseif ($cash == 30) {
|
||
|
return 10561;
|
||
|
} elseif ($cash == 50) {
|
||
|
return 10562;
|
||
|
} elseif ($cash == 100) {
|
||
|
return 10563;
|
||
|
} elseif ($cash == 200) {
|
||
|
return 10564;
|
||
|
} elseif ($cash == 300) {
|
||
|
return 10565;
|
||
|
} elseif ($cash == 500) {
|
||
|
return 10566;
|
||
|
}
|
||
|
} elseif ($this->teltype == 2) {
|
||
|
if ($cash == 10) {
|
||
|
return 10567;
|
||
|
} elseif ($cash == 20) {
|
||
|
return 10568;
|
||
|
} elseif ($cash == 30) {
|
||
|
return 10569;
|
||
|
} elseif ($cash == 50) {
|
||
|
return 10570;
|
||
|
} elseif ($cash == 100) {
|
||
|
return 10571;
|
||
|
} elseif ($cash == 200) {
|
||
|
return 10572;
|
||
|
} elseif ($cash == 300) {
|
||
|
return 10573;
|
||
|
} elseif ($cash == 500) {
|
||
|
return 10574;
|
||
|
}
|
||
|
} elseif ($this->teltype == 3) {
|
||
|
if ($cash == 10) {
|
||
|
return 10575;
|
||
|
} elseif ($cash == 20) {
|
||
|
return 10576;
|
||
|
} elseif ($cash == 30) {
|
||
|
return 10577;
|
||
|
} elseif ($cash == 50) {
|
||
|
return 10578;
|
||
|
} elseif ($cash == 100) {
|
||
|
return 10579;
|
||
|
} elseif ($cash == 200) {
|
||
|
return 10580;
|
||
|
} elseif ($cash == 300) {
|
||
|
return 10581;
|
||
|
} elseif ($cash == 500) {
|
||
|
return 10582;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return 0000;
|
||
|
}
|
||
|
|
||
|
private function _sign($request, $param)
|
||
|
{
|
||
|
$request['userId'] = $this->mid;
|
||
|
$request['key'] = $this->token;
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
if (isset($request[$v]) && $request[$v]) {
|
||
|
$signature_string .= $request[$v];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
}
|