303 lines
7.7 KiB
PHP
Raw Normal View History

<?php
namespace app\channel\service\system;
/**
* 服务
* Class Tiancheng
* @package app\channel\service
*/
class Feedov extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $api = '';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'target',
);
if(isset($param['mobile'])){
unset($check['account']);
$check['mobile'] = 'target';
}
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
# 话费充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'target',
);
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
public function ydcz_alipay($param)
{
$check = array
(
'mobile' => 'target',
'operator_id'=>'operator_id',
);
$param['operator_id'] = '移动';
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
public function dxcz_card($param)
{
$check = array
(
'mobile' => 'target',
'operator_id'=>'operator_id',
);
$param['operator_id'] = '电信';
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
public function dxcz_lt_mnp($param)
{
$check = array
(
'mobile' => 'target',
'operator_id'=>'operator_id',
);
$param['operator_id'] = '电信';
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
# 话费充值
public function ydcz($param)
{
$check = array
(
'mobile' => 'target',
'operator_id'=>'operator_id',
);
$param['operator_id'] = '移动';
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
public function ltcz($param)
{
$check = array
(
'mobile' => 'target',
'operator_id'=>'operator_id',
);
$param['operator_id'] = '联通';
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
public function dxcz($param)
{
$check = array
(
'mobile' => 'target',
'operator_id'=>'operator_id',
);
$param['operator_id'] = '电信';
$this->api = 'api/merchant/upload_order';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
if ($data['state'] == 3) {
$result['status'] = 2;
} elseif ($data['state'] == 4) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['voucher']) && $data['voucher']) {
# 流水号
$data['s_number'] = $result['s_number'] = $data['voucher'];
}
if(isset($data['card_no']) && $data['card_no']){
$data['s_number'] = $result['s_number'] = '卡号:'.$data['card_no'];
}
if (isset($data['info']) && $data['info']) {
$data['msg'] = $result['msg'] = $data['info'];
}
if(isset($data['cost']) && $data['cost']){
$result['channel_cost'] = $data['cost'];
}
$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'] == '0') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['message']) ? $array['message'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $array,
'array' => $array,
);
}
# 查询接口
public function query($order){
$request['app_key'] = $this->mid;
if(isset($order['channel_order_id']) && $order['channel_order_id']){
$request['order_id'] = $order['channel_order_id'];
}else{
$request['third_id'] = $order['merchant_order_id'];
// $request['time'] = timestamp($order['order']);
}
$request['timestamp'] = time();
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/merchant/order_info';
$response = $this->curl('post', $url, $request);
#记录日志
$log['type'] = 'query_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
#记录借宿
$array = $this->json_decode($response,true);
$result = array();
$result['status'] = 4;
if ($array['code']=='ok' ) {
if($array['state'] ==3){
$result['query_status'] = 3;
$result['status'] = 2;
}elseif ($array['state'] == 4){
$result['query_status'] = 4;
$result['status'] = 3;
}
}
return $result;
}
# 查询余额接口
public function account($day)
{
$request['app_key'] = $this->mid;
$request['timestamp']=time();
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/merchant/account';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
$datas = $response['array']['data'];
if(is_array($datas) && isset($datas['amount']) && $datas['amount'] ){
$datas['account'] = $datas['amount']; //此处为余额
}
return $datas;
}
# 提交数据
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
$request=[];
$request['app_key'] = $this->mid;
$request['third_id'] = $param['order'];
$request['miniunit_id'] = $this->getGid($param['cash']);
$request['timestamp'] = time();
// $request['call_back_url'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request);
// $param['detail']['target'] = intval($param['detail']['target']);
$request['datas'] = $param['detail'];
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request, true);
$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);
$buff = '';
foreach ($request as $k => $v) {
if ($k != "sign" && $k != "datas") {
$buff .= $k . $v;
}
}
//连接加密串
$buff .= $this->token;
return md5($buff);
}
}