REAPI/app/channel/service/system/Qizhixiong.php

220 lines
6.3 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
use app\channel\service\CardService;
use app\merchant\service\OrderService;
/**
* 七只熊服务:卡密专用
* Class Qizhixiong
* @package app\channel\service
*/
class Qizhixiong extends Core
{
# 这几个可以后台设置
protected $host = 'http://youka.5dev.cn/';
protected $mid = 'app318205390881';
protected $token = 'BY0NXHGS103VPCORAX8V8MJBTTTSNLVC';
protected $card = array();
protected $order_id = '';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'account',
'cash' => 'cash',
'api_product' => 'api_product',
);
$param['api_product'] = 'dycz';
return $this->submit($param, $check);
}
# 电话充值 拼音来吧
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'api_product' => 'api_product',
);
$param['api_product'] = 'dhcz';
return $this->submit($param, $check);
}
# 中石化卡密充值
public function zshcz($param)
{
return $this->dxdc($param);
}
# 系统代充
public function xtdc($param)
{
$check = array
(
'card' => 'card',
'cash' => 'cash',
'cnum' => 'cnum',
'cpwd' => 'cpwd',
'api_product' => 'api_product',
);
if (!isset($param['cnum'])) {
$data = CardService::instance()->getOne($param['cash']);
if ($data) {
$this->data['param']['cnum'] = $param['cnum'] = $data['cnum'];
$this->data['param']['cpwd'] = $param['cpwd'] = $data['cpwd'];
$this->card = $data;
$this->card_id = $this->card['id'];
} else {
return 'card error';
}
}
$param['api_product'] = 'dxdc';
return $this->submit($param, $check);
}
# 短信代充
public function dxdc($param)
{
$check = array
(
'card' => 'card',
'cash' => 'cash',
//'cnum' => 'cnum',
//'cpwd' => 'cpwd',
'api_product' => 'api_product',
);
$param['api_product'] = 'xtdc';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['signature']);
$this->token = $this->mid . '|' . $this->token;
$request = $this->getParam($request, $this->token);
if ($request['signature'] != $data['signature']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['status'] == 2) {
$result['status'] = 2;
} elseif ($data['status'] == 3) {
$result['status'] = 3;
} elseif ($data['status'] == 5) {
$result['status'] = 5;
} else {
$result['status'] = 4;
}
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'];
}
$order = OrderService::instance()->get($data['merchant_order_id']);
if ($order && $order['card_id'] > 0) {
if ($result['status'] == 2) {
CardService::instance()->log($order, 5, '充值成功');
} elseif ($result['status'] == 3) {
CardService::instance()->log($order, 6, '渠道充值失败');
} elseif ($result['status'] == 5) {
CardService::instance()->log($order, 7, '卡密充值失败');
}
}
$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['info']) ? $array['info'] : 'error';
}
# 增加卡密日志
$order = array();
if ($this->order_id) {
$order = OrderService::instance()->get($this->order_id);
if ($order && $order['card_id'] > 0) {
if ($msg == 'ok') {
CardService::instance()->log($order, 3, '渠道下单成功');
} else {
CardService::instance()->log($order, 4, '渠道下单失败');
}
}
}
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;
}
return $this->send($param);
}
private function send($param, $parent_order = '')
{
$request = $param['detail'];
$request['appid'] = $this->mid;
$this->order_id = $request['order'] = $param['order'];
$this->token = $this->mid . '|' . $this->token;
$request = $this->getParam($request, $this->token);
$url = $this->host . 'gateway/api.handle/submit';
$response = $this->curl('post', $url, $request);
//$response = '{"code":1,"info":"ok","data":{"order":"M202103263150293472974607","account":"1000115200004408960","status":1}}';
$response = $this->response($response);
//$response['data'] = '{}';
//$response['msg'] = 'ok';
$channel_order_id = '';
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'], $parent_order, $this->card_id);
return $response['msg'];
}
}