217 lines
6.3 KiB
PHP
217 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 话费服务
|
|
* Class Common
|
|
* @package app\channel\service
|
|
*/
|
|
class Flow extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'host';
|
|
protected $mid = 'mid';
|
|
protected $token = 'token';
|
|
protected $api = 'api';
|
|
|
|
# 电话充值
|
|
public function common($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'mobile',
|
|
'cash' => 'cash',
|
|
'ispCode' => 'ispCode',
|
|
);
|
|
$param['isp'] = $this->isp($param['mobile']);
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
if ($param['isp'] == 1) {
|
|
$param['ispCode'] = 'CMCC';
|
|
} elseif ($param['isp'] == 2) {
|
|
$param['ispCode'] = 'CUCC';
|
|
} elseif ($param['isp'] == 3) {
|
|
$param['ispCode'] = 'CTCC';
|
|
}
|
|
}
|
|
$this->api = 'flow-receiver/api/recharge/feecbk';
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 电话充值
|
|
public function dhcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'mobile',
|
|
'cash' => 'cash',
|
|
'ispCode' => 'ispCode',
|
|
);
|
|
$param['isp'] = $this->isp($param['mobile']);
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
if ($param['isp'] == 1) {
|
|
$param['ispCode'] = 'CMCC';
|
|
} elseif ($param['isp'] == 2) {
|
|
$param['ispCode'] = 'CUCC';
|
|
} elseif ($param['isp'] == 3) {
|
|
$param['ispCode'] = 'CTCC';
|
|
}
|
|
}
|
|
$this->api = 'flow-receiver/api/recharge/feecbk';
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['status'] == '001') {
|
|
$result['status'] = 2;
|
|
} elseif ($data['status'] == '003') {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 3;
|
|
}
|
|
if (isset($data['voucherNo']) && $data['voucherNo'] && $data['voucherNo'] != 'null') {
|
|
# 流水号
|
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['voucherNo'];
|
|
}
|
|
|
|
$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['status']) && $array['status'] == '001') {
|
|
# 正确
|
|
$msg = 'ok';
|
|
} else {
|
|
# 错误
|
|
$msg = isset($array['status']) ? $array['status'] : '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'];
|
|
unset($request['cash']);
|
|
$request['account'] = $this->mid;
|
|
list($msec, $sec) = explode(' ', microtime());
|
|
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
|
$msec = substr($msectime,0,13);
|
|
$request['timestamp'] = $msec;
|
|
$request['consumerNo'] = $param['order'];
|
|
//$request['flowCode'] = $this->getCode($param['cash'], $request['ispCode']);
|
|
$request['flowCode'] = $this->getGid($param['cash']);
|
|
//$request['cbkUrl'] = $this->getNotify($param['order'], 1);
|
|
$request['cbkUrl'] = 'http://125.124.84.185:8081/gateway/api.notify/flow_call';
|
|
$request['sign'] = $this->_sign($request);
|
|
$url = $this->host . $this->api;
|
|
$response = $this->curl('get', $url, $request);
|
|
// print_r($request);
|
|
// print_r($response);die;
|
|
$response = $this->response($response);
|
|
//$response['data'] = '';
|
|
//$response['msg'] = 'ok';
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['orderNo'])) {
|
|
$channel_order_id = $response['array']['orderNo'];
|
|
}
|
|
|
|
$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)
|
|
{
|
|
$signature = array($this->token, $request['timestamp'], $request['account']);
|
|
sort($signature, SORT_STRING);
|
|
$signature = implode($signature );
|
|
$signature = sha1($signature );
|
|
|
|
return $signature;
|
|
}
|
|
|
|
private function getCode($cash, $type)
|
|
{
|
|
if ($type == 'CMCC') {
|
|
if ($cash == 50) {
|
|
return 'def_zsh_50';
|
|
} elseif ($cash == 100) {
|
|
return 'def_zsh_100';
|
|
} elseif ($cash == 200) {
|
|
return 'def_zsh_200';
|
|
} elseif ($cash == 500) {
|
|
return 'def_zsh_500';
|
|
} elseif ($cash == 1000) {
|
|
return 'def_zsh_1000';
|
|
}
|
|
}
|
|
|
|
if ($type == 'CUCC') {
|
|
if ($cash == 50) {
|
|
return 'def_zsh_50';
|
|
} elseif ($cash == 100) {
|
|
return 'def_zsh_100';
|
|
} elseif ($cash == 200) {
|
|
return 'def_zsh_200';
|
|
} elseif ($cash == 500) {
|
|
return 'def_zsh_500';
|
|
} elseif ($cash == 1000) {
|
|
return 'def_zsh_1000';
|
|
}
|
|
}
|
|
|
|
if ($type == 'CTCC') {
|
|
if ($cash == 50) {
|
|
return 'def_zsh_50';
|
|
} elseif ($cash == 100) {
|
|
return 'def_zsh_100';
|
|
} elseif ($cash == 200) {
|
|
return 'def_zsh_200';
|
|
} elseif ($cash == 500) {
|
|
return 'def_zsh_500';
|
|
} elseif ($cash == 1000) {
|
|
return 'def_zsh_1000';
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |