2024-09-29 15:43:18 +08:00

288 lines
9.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\channel\service\system;
use app\channel\service\CardService;
/**
* 乐购代发
* Class Tiancheng
* @package app\channel\service
*/
class Legou extends Core
{
# 这几个可以后台设置
protected $host = 'https://recv.shujubuy.com/';
protected $mid = 'qzxsms';
protected $token = '045a8ffc-9a3d-42b3-ac78-2bc05ac8a841';
protected $card = array();
protected $order_id = '';
protected $productNo = 0;
# 系统代充
public function xtdc($param)
{
$check = array
(
'card' => 'cardNumber',
'cash' => 'cardExt',
'cnum' => 'rechargeNum',
'cpwd' => 'rechargePwd',
);
if (!isset($param['cnum'])) {
$data = CardService::instance()->getData($param['cash'], $this->data['merchant']);
if ($data) {
$this->data['param']['cnum'] = $param['cnum'] = $data['cnum'];
$this->data['param']['cpwd'] = $param['cpwd'] = $data['cpwd'];
$this->card = $data;
} else {
return 'card error';
}
}
$this->productNo = 400001;
return $this->submit($param, $check);
}
# 短信代充
public function dxdc($param)
{
$check = array
(
'card' => 'cardNumber',
'cash' => 'cardExt',
'cnum' => 'rechargeNum',
'cpwd' => 'rechargePwd',
);
$this->productNo = 400001;
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'cardNumber',
'cash' => 'cardExt',
);
$this->productNo = 204010;
if ($param['cash'] == 200) {
$this->productNo = 204020;
} elseif ($param['cash'] == 500) {
$this->productNo = 204050;
} elseif ($param['cash'] == 1000) {
$this->productNo = 204100;
} elseif ($param['cash'] == 2000) {
$this->productNo = 204200;
}
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$sign = $this->_sign($request);
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['status'] = false;
$result['cash'] = floatval($data['orderMoney']);
if (strstr($data['rechargeDesc'], '{')) {
$desc = json_decode($data['rechargeDesc'], true);
if (isset($desc['rechargeStatus']) && $desc['rechargeStatus']) {
if ($desc['rechargeStatus'] == 600200) {
$result['status'] = 2;
} elseif ($desc['rechargeStatus'] == 600201 || $desc['rechargeStatus'] == 600201 || $desc['rechargeStatus'] == 600300) {
$result['status'] = 4;
} else {
$result['status'] = 3;
}
}
}
if (!$result['status']) {
if ($data['resultCode'] == 2) {
$result['status'] = 2;
} elseif ($data['resultCode'] == 3) {
$result['status'] = 3;
} else {
//$result['status'] = 3;
//存疑
$result['status'] = 5;
}
}
//成功短信 【中国石化】您尾号为444562的加油卡于01月05日 17时37分充值成功,金额200元,订单号:2521010517376142 这是成功的短信内容
//充值过 【中国石化】充值卡卡密[33412927463390117830]验证失败,请重新发送充值短信!
if (isset($this->data['merchant']) && $this->data['merchant'] == 48) {
$data['rechargeVoucher'] = '';
}
if (isset($data['rechargeVoucher']) && $data['rechargeVoucher']) {
# 错误信息
$data['msg'] = $result['msg'] = $data['rechargeVoucher'];
}
if ($result['status'] == 2 && isset($result['msg']) && $result['msg']) {
# 充值成功,分析短信
$temp = explode(':', $result['msg']);
$order = $temp[1];
if (strstr($order, '')) {
$temp = explode('', $order);
$order = $temp[0];
}
$data['s_nubmer'] = $result['s_nubmer'] = $order;
}
$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']['status']) && $array['code']['status'] == '100000') {
# 正确
$msg = 'ok';
if ($this->card) {
CardService::instance()->yes($this->card['id'], $this->data['merchant'], $this->order_id);
}
} else {
# 错误
$msg = isset($array['code']['desc']) ? $array['code']['desc'] : 'error';
# 下单失败
if ($this->card) {
CardService::instance()->no($this->card['id'], $this->data['merchant'], $this->order_id);
}
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
public function encrypt($value, $key = false, $iv = false)
{
if (!$key) {
//$key = str_replace('-', '', $this->token);
$key = $this->token;
$iv = substr($key, -16, 16);
$key = substr($key, 0, 16);
}
$data = openssl_encrypt($value, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
$data = base64_encode($data);
return $data;
}
# 查询接口
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'];
$request['username'] = $this->mid;
$this->order_id = $request['orderNumber'] = $param['order'];
$request['timestamp'] = $this->timestamp();
$request['productNo'] = $this->productNo;
$request['sign'] = $this->_sign($request);
if (isset($request['rechargeNum']) && $request['rechargeNum']) {
$request['rechargeNum'] = $this->encrypt($request['rechargeNum']);
}
if (isset($request['rechargePwd']) && $request['rechargePwd']) {
$request['rechargePwd'] = $this->encrypt($request['rechargePwd']);
}
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
$url = $this->host . 'api/recv/submitOrder';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
/*
if (isset($response['array']['obj']) && $response['array']['obj']) {
$channel_order_id = $response['array']['obj'];
}
*/
$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);
$string = '';
$string .= $request['username'];
$string .= $request['orderNumber'];
$string .= $request['cardNumber'];
if (isset($request['cardExt']) && $request['cardExt']) {
$string .= $request['cardExt'];
}
if (isset($request['rechargeNum']) && $request['rechargeNum']) {
$string .= $request['rechargeNum'];
}
if (isset($request['rechargePwd']) && $request['rechargePwd']) {
$string .= $request['rechargePwd'];
}
if (isset($request['orderMoney']) && $request['orderMoney']) {
$string .= $request['orderMoney'];
}
if (isset($request['orderPay']) && $request['orderPay']) {
$string .= $request['orderPay'];
}
if (isset($request['resultCode']) && $request['resultCode']) {
$string .= $request['resultCode'];
}
if (isset($request['rechargeDesc']) && $request['rechargeDesc']) {
$string .= $request['rechargeDesc'];
}
if (isset($request['productNo']) && $request['productNo']) {
$string .= $request['productNo'];
}
if (isset($request['timestamp']) && $request['timestamp']) {
$string .= $request['timestamp'];
}
return md5($string . $this->token);
}
/**
* timestamp
*
* @return mixed
*/
public function timestamp()
{
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
return $msectime;
}
}