199 lines
5.4 KiB
PHP
199 lines
5.4 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 欢度
|
||
|
* Class Huandu
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Xiaoya extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $api = '';
|
||
|
protected $sign = array();
|
||
|
protected $region = '';
|
||
|
|
||
|
# 通用的充值
|
||
|
public function common($param)
|
||
|
{
|
||
|
return $this->dhcz($param);
|
||
|
}
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'mobile',
|
||
|
'cash' => 'amount',
|
||
|
'carrier' => 'carrier',
|
||
|
);
|
||
|
|
||
|
if (isset($param['isp']) && $param['isp']) {
|
||
|
if ($param['isp'] == 1) {
|
||
|
$param['carrier'] = 'CMCC';
|
||
|
} elseif ($param['isp'] == 2) {
|
||
|
$param['carrier'] = 'CUCC';
|
||
|
} elseif ($param['isp'] == 3) {
|
||
|
$param['carrier'] = 'CTCC';
|
||
|
}
|
||
|
}
|
||
|
$this->api = '/order/launch';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['status'] == 'S') {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['status'] == 'F') {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
if (isset($data['carrier_order_no']) && $data['carrier_order_no']) {
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['carrier_order_no'];
|
||
|
}
|
||
|
|
||
|
$result['yes'] = 'OK';
|
||
|
|
||
|
$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'] == 'OK') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['message']) ? $array['message'] : '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'];
|
||
|
$fs = -1;
|
||
|
if (strstr($this->mid, '|')) {
|
||
|
$temp = explode('|', $this->mid);
|
||
|
$this->mid = $temp[0];
|
||
|
if (isset($temp[1])) {
|
||
|
$fs = $temp[1];
|
||
|
}
|
||
|
}
|
||
|
if ($fs == 1) {
|
||
|
list($region, $isp) = $this->isp($param['mobile']);
|
||
|
$this->region($region);
|
||
|
$request['region'] = $this->region;
|
||
|
} elseif ($fs == 2) {
|
||
|
$request['region'] = $this->getGid($param['cash']);
|
||
|
}
|
||
|
|
||
|
$request['vendor_no'] = $this->mid;
|
||
|
$request['order_no'] = $param['order'];
|
||
|
$request['longterm'] = 'N';
|
||
|
$request['callback_url'] = $this->getNotify($param['order'], 1);
|
||
|
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
|
||
|
$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']['platform_order_no'])) {
|
||
|
$channel_order_id = $response['array']['platform_order_no'];
|
||
|
}
|
||
|
|
||
|
$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 .= 'key=' . $this->token;
|
||
|
|
||
|
return strtoupper(md5($signature_string));
|
||
|
}
|
||
|
|
||
|
public function isp($mobile)
|
||
|
{
|
||
|
$url = 'http://cx.shouji.360.cn/phonearea.php?number=' . $mobile;
|
||
|
|
||
|
$data = $this->curl('get', $url);
|
||
|
|
||
|
if ($data) {
|
||
|
$data = json_decode($data, true);
|
||
|
if ($data && isset($data['data']['sp'])) {
|
||
|
$sp = $data['data']['sp'];
|
||
|
if ($sp == '移动') {
|
||
|
return array($data['data']['province'], 1);
|
||
|
} elseif ($sp == '联通') {
|
||
|
return array($data['data']['province'], 2);
|
||
|
} elseif ($sp == '电信') {
|
||
|
return array($data['data']['province'], 3);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return array('未知', 4);
|
||
|
}
|
||
|
|
||
|
protected function region($region)
|
||
|
{
|
||
|
if (strstr($region, '福建')) {
|
||
|
$this->region = 35;
|
||
|
}
|
||
|
if (strstr($region, '云南')) {
|
||
|
$this->region = 53;
|
||
|
}
|
||
|
$this->region = '00';
|
||
|
}
|
||
|
}
|