263 lines
7.8 KiB
PHP
263 lines
7.8 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 服务
|
||
|
* Class Tiancheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Kakayun extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $method = '';
|
||
|
protected $api = '';
|
||
|
|
||
|
# 电话充值 拼音来吧
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'attach',
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
$param['api_product'] = 'dhcz';
|
||
|
$this->api='dockapi/index/buy';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
public function cardbuy($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
$param['api_product'] = 'cardbuy';
|
||
|
$this->api='dockapi/index/buy';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
public function yxkm_cardbuy($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'cash' => 'cash',
|
||
|
);
|
||
|
$param['api_product'] = 'cardbuy';
|
||
|
$this->api='dockapi/index/buy';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
# 中石油油卡充值 拼音来吧
|
||
|
public function zsycz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'card',
|
||
|
'cash' => 'cash',
|
||
|
//'idCard' => 'idCard',
|
||
|
//'realName' => 'realName',
|
||
|
'api_product' => 'api_product',
|
||
|
);
|
||
|
$param['api_product'] = 'zsycz';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function zshcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'card',
|
||
|
'cash' => 'cash',
|
||
|
'api_product' => 'api_product',
|
||
|
);
|
||
|
$param['api_product'] = 'zshcz_tc';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值透传
|
||
|
public function zshcz_tc($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'card',
|
||
|
'cash' => 'cash',
|
||
|
'api_product' => 'api_product',
|
||
|
);
|
||
|
$param['api_product'] = 'zshcz_tc';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
unset($request['sign']);
|
||
|
// $request = $this->getParam($request, $this->token, 2);
|
||
|
// if ($request['signature'] != $data['signature']) {
|
||
|
// return false;
|
||
|
// }
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
$result['status'] = 4;
|
||
|
if(isset($data['query_status']))$data['status'] = $data['query_status'];
|
||
|
if(isset($data['status'])){
|
||
|
if ($data['status'] == 5) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['status'] == 4) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
if (isset($this->data['product_key']) && strstr($this->data['product_key'], '_tc') && isset($data['vnum']) && $data['vnum']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['vnum'];
|
||
|
}
|
||
|
*/
|
||
|
if (isset($data['s_nubmer']) && $data['s_nubmer']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['s_nubmer'];
|
||
|
}
|
||
|
|
||
|
if (isset($data['msg']) && $data['msg']) {
|
||
|
# 错误信息
|
||
|
$data['msg'] = $result['msg'] = $data['msg'];
|
||
|
}
|
||
|
|
||
|
// $result['data'] = $data;
|
||
|
$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'] == 1) {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['msg']) ? $array['msg'] : 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 查询接口
|
||
|
public function query($order)
|
||
|
{
|
||
|
$request['userid'] = $this->mid;
|
||
|
$request['orderno'] = $order['order_id'];
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
$url = $this->host . 'dockapi/index/queryorder';
|
||
|
$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 (isset($array['code'])&&$array['code']==1 ) {
|
||
|
if($array['data']['status'] ==5){
|
||
|
$result['query_status'] = 5;
|
||
|
|
||
|
$result['status'] = 2;
|
||
|
}elseif ($array['data']['status'] == 4){
|
||
|
$result['query_status'] = 4;
|
||
|
$result['status'] = 3;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
if(isset($array['cardlist'])){
|
||
|
$result['kami']=array(
|
||
|
// 'cardno' => isset($array['data']['cards'][0]['card_no'])?$array['data']['cards'][0]['card_no']:'',
|
||
|
// 'cardpwd' => $array['data']['cards'][0]['card_password'],
|
||
|
// 'expired' => $array['data']['cards'][0]['expired_at'],
|
||
|
);
|
||
|
}
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
# 查询余额接口
|
||
|
public function account($day)
|
||
|
{
|
||
|
$request['day'] = $day;
|
||
|
$request['appid'] = $this->mid;
|
||
|
$request['api_product'] = 'query';
|
||
|
$request = $this->getParam($request, $this->token, 2);
|
||
|
$url = $this->host . 'gateway/api.handle/accountByDay';
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
|
||
|
return $response['array']['data'];
|
||
|
}
|
||
|
|
||
|
# 提交数据
|
||
|
private function submit($param, $check,$is_kami=false)
|
||
|
{
|
||
|
$param = $this->param($param, $check);
|
||
|
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
|
return $param;
|
||
|
}
|
||
|
|
||
|
return $this->send($param,'',$is_kami);
|
||
|
}
|
||
|
|
||
|
private function send($param, $parent_order = '',$is_kami=false)
|
||
|
{
|
||
|
$request = $param['detail'];
|
||
|
$request['userid'] = $this->mid;
|
||
|
$request['goodsid'] = $this->getGid($param['cash']);
|
||
|
unset($request['cash']);
|
||
|
$request['outorderno'] = $param['order'];
|
||
|
$request['buynum'] = 1;
|
||
|
$request['notify'] = $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 = '';
|
||
|
|
||
|
// $this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'], $parent_order);
|
||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'],isset($response['array']['money'])?$response['array']['money']:$param['cash'] , $url, $request, $response, 1, $param['account'], $parent_order);
|
||
|
|
||
|
return $response['msg'];
|
||
|
}
|
||
|
private function _sign($param){
|
||
|
ksort($param); //排序post参数
|
||
|
reset($param); //内部指针指向数组中的第一个元素
|
||
|
$signtext='';
|
||
|
foreach ($param AS $key => $val) { //遍历POST参数
|
||
|
if ($val == '' || $key == 'sign') continue; //跳过这些不签名
|
||
|
if ($signtext) $signtext .= '&'; //第一个字符串签名不加& 其他加&连接起来参数
|
||
|
$signtext .= "$key=$val"; //拼接为url参数形式
|
||
|
}
|
||
|
$newsign=md5($signtext.$this->token);
|
||
|
return $newsign;
|
||
|
}
|
||
|
}
|