183 lines
4.6 KiB
PHP
183 lines
4.6 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 话费服务
|
||
|
* Class Common
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class younakang extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
protected $Operator = 'dhcz';
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
|
||
|
return $this->dhcz_submit_pram($param);
|
||
|
}
|
||
|
|
||
|
# 电话充值
|
||
|
public function ydcz($param)
|
||
|
{
|
||
|
$param['operator'] = 'CM';
|
||
|
|
||
|
return $this->dhcz_submit_pram($param);
|
||
|
}
|
||
|
|
||
|
# 电话充值
|
||
|
public function dxcz($param)
|
||
|
{
|
||
|
$param['operator'] = 'CT';
|
||
|
|
||
|
return $this->dhcz_submit_pram($param);
|
||
|
}
|
||
|
|
||
|
# 电话充值
|
||
|
public function ltcz($param)
|
||
|
{
|
||
|
$param['operator'] = 'CU';
|
||
|
|
||
|
|
||
|
return $this->dhcz_submit_pram($param);
|
||
|
}
|
||
|
|
||
|
public function dhcz_submit_pram($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'cash' => 'productValue',
|
||
|
'mobile' => 'phoneNumber',
|
||
|
|
||
|
);
|
||
|
$this->api = '/api/tel/createOrder';
|
||
|
|
||
|
return $this->submit($param, $check);
|
||
|
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
unset($request['sign']);
|
||
|
unset($request['s_order']);
|
||
|
$sign = strtoupper($this->_sign($request));
|
||
|
// $sign = strtoupper($this->sign($request, 'md5', '&appSecret=' . $this->token));
|
||
|
if ($sign != $data['key']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
// $result['cash'] = 1;
|
||
|
if ($data['code'] == 0||$data['code']==20000) {
|
||
|
$result['status'] = 2;
|
||
|
} else {
|
||
|
$result['status'] = 3;
|
||
|
}
|
||
|
|
||
|
$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'] == 'success') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['message']) ? $array['message'] : 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 查询接口
|
||
|
public function query($param)
|
||
|
{
|
||
|
if (empty($param['order'])) {
|
||
|
return 'order';
|
||
|
}
|
||
|
$request['appId'] = $this->mid;
|
||
|
$request['orderId'] = $param['order'];
|
||
|
$request['key'] = $this->_sign($request);
|
||
|
|
||
|
$url = $this->host . '/api/tel/queryOrder';
|
||
|
return $this->response($this->curl('post', $url, $request, true));
|
||
|
}
|
||
|
|
||
|
|
||
|
# 账户余额
|
||
|
public function account(){
|
||
|
$request['appId'] = $this->mid;
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
$url = $this->host . '/api/getUserBalance';
|
||
|
return $this->response($this->curl('get', $url, $request, true));
|
||
|
}
|
||
|
|
||
|
|
||
|
# 提交数据
|
||
|
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['appId'] = $this->mid;
|
||
|
$request['orderId'] = $param['order'];
|
||
|
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
|
||
|
$request['key'] = strtoupper($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 = '';
|
||
|
if (isset($response['orderId'])) {
|
||
|
$channel_order_id = $response['orderId'];
|
||
|
}
|
||
|
|
||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
|
return $response['message'];
|
||
|
}
|
||
|
|
||
|
private function _sign($request)
|
||
|
{
|
||
|
ksort($request);
|
||
|
$signature_string = '';
|
||
|
foreach ($request as $k => $v) {
|
||
|
if (isset($request[$k]) && $request[$k]) {
|
||
|
$signature_string .= $k . '' . $request[$k];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$signature_string .= $this->token;
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
}
|