170 lines
4.6 KiB
PHP
170 lines
4.6 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 话费服务
|
||
|
* Class Common
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Whui extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'phone',
|
||
|
'cash' => 'amount',
|
||
|
'way' => 'way',
|
||
|
'operator' => 'operator',
|
||
|
'region' => 'region',
|
||
|
);
|
||
|
$this->api = 'subCharge';
|
||
|
|
||
|
list($region, $isp) = $this->isp($param['mobile']);
|
||
|
$paytype = '';
|
||
|
if ($isp == 1) {
|
||
|
$paytype = '801';
|
||
|
}
|
||
|
if ($isp == 2) {
|
||
|
$paytype = '803';
|
||
|
}
|
||
|
if ($isp == 3) {
|
||
|
$paytype = '802';
|
||
|
}
|
||
|
$param['way'] = $paytype;
|
||
|
$param['operator'] = $isp;
|
||
|
$param['region'] = $region;
|
||
|
|
||
|
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;
|
||
|
} else {
|
||
|
$result['status'] = 3;
|
||
|
}
|
||
|
if (isset($data['remark1']) && $data['remark1']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['remark1'];
|
||
|
}
|
||
|
|
||
|
$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['data']['code']) && $array['data']['code'] == '10000') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['data']['msg']) ? $array['data']['msg'] : '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'];
|
||
|
$request['method'] = 'substitute';
|
||
|
$request['member_id'] = $this->mid;
|
||
|
$request['order_id'] = $param['order'];
|
||
|
$request['expire_time'] = '3600';
|
||
|
$request['sign_type'] = 'MD5';
|
||
|
$request['notify_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);
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['data']['order_id'])) {
|
||
|
$channel_order_id = $response['array']['data']['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) {
|
||
|
if ($v) {
|
||
|
$signature_string .= $k . '=' . $v . '&';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$signature_string .= 'key=' . $this->token;
|
||
|
|
||
|
return strtoupper(md5($signature_string));
|
||
|
}
|
||
|
|
||
|
public function isp($mobile)
|
||
|
{
|
||
|
//return $this->getphonetype($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);
|
||
|
}
|
||
|
}
|