mzeros 84856367e9 feat(openapi): 新增码速达API接口
- 添加AfterSales类处理售后服务相关接口
- 新增ContentTemplate控制器和模型用于内容模板管理
- 添加diandian渠道服务类
- 更新Feedov控制器和添加FeedovHfAuto命令类
- 新增autoCard视图用于自动发卡设置
2025-03-11 00:17:40 +08:00

258 lines
6.3 KiB
PHP
Raw Permalink 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\merchant\service\MerchantService;
use app\merchant\service\OrderService;
/**
* 讯银服务
* Class Bodingcheng
* @package app\channel\service
*/
class Jiaolian extends Core
{
# 这几个可以后台设置
protected $host = 'http://58.220.211.41:12009/';
protected $mid = '61';
protected $token = '31HHu6R4';
protected $api = '';
protected $deskey = '8710fa8219cc4c9b9f96165e';
protected $goodid = '';
# 购买卡密
public function cardbuy($param)
{
// var_dump($param);die;
$check = array
(
'cash' => 'code',
'account' => 'account',
'num' => 'number',
);
$this->api = 'api/order/tk';
return $this->submit($param, $check);
}
# 数据响应格式处理
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' ) {
# 正确
if(isset($array['data']['cardNoData'])){
$msg = 'yescard';
$kami = $this->decrypt_3des($array['data']['cardNoData']);
if($kami){
$kami = explode(',', $kami);
$array['kami'] = [
'cardno' => $kami[0],
'cardpwd' => $kami[1],
'expired' => $kami[2]??'',
];
}else{
$msg = 'ok';
}
}else{
$msg = 'ok';
}
# 正确
} else {
# 错误
$msg = $array['msg'] ?? 'error';
}
return array
(
'msg' => $msg,
'data' => $array,
'array' => $array,
);
}
# 查询接口
public function query($order)
{
$request['appid'] = $this->mid;
$request['orderNo'] = $order['order_id'];
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/order/tkQuery';
$response = $this->curl('post', $url, $request,true);
$log['type'] = 'query_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
$array = $this->json_decode($response);
$array['status'] = 4;
if (isset($array['code']) && $array['code'] == '0' ) {
# 正确
if(isset($array['data']['cardNoData'])){
$msg = 'yescard';
$kami = $this->decrypt_3des($array['data']['cardNoData']);
if($kami){
$kami = explode(',', $kami);
$array['kami'] = [
'cardno' => $kami[0],
'cardpwd' => $kami[1],
'expired' => $kami[2]??'',
];
$this->upOrderResponse( $array['kami'],$order['merchant_order_id'],$order['response']);
$array['status'] = 7;
}else{
$array['status'] = 2;
}
}
} else {
$array['status'] = 3;
}
return $array;
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$result = array();
$result['cash'] = 1;
$result['status'] = $data['status'] ;
if (isset($data['kami']) && $data['kami']['cardno']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['kami']['cardno'];
}
$result['yes'] = 'ok';
$result['data'] = $data;
return $result;
}
# 提交数据
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
// var_dump($param);die;
$request = $param['detail'];
$request['appid'] = $this->mid;
$request['type'] = $this->getGid($param['cash']);
$request['orderNo'] = $param['order'];
$request['is_dynamic'] = 0;
$request['sign'] = $this->_sign($request);
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request,true);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['data']['orderNo'])) {
$channel_order_id = $response['array']['data']['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_string = '';
ksort($request);
foreach ($request as $k => $v) {
// if (isset($request[$v]) && $request[$v]) {
$signature_string .= $k . '=' . $v . '&';
}
$signature_string .= 'key='.($this->token);
$sign = MD5($signature_string);
// var_dump($signature_string);die;
// $signature_string = iconv("UTF-8", "gbk", $signature_string);
return strtoupper($sign);
}
#3des解密
public function decrypt_3des($encrypted_string){
$cipher = "des-ede3"; // 3des-ebc 使用的是des-ede3算法
$mode = "ebc"; // 工作模式为ebc
$iv = ""; // EBC模式不需要IV留空即可
$json = $this->channel['other_data'];
$array = $this->json_decode($json);
if(isset($array['aeskey'])){
$this->deskey = $array['aeskey'];
}
return openssl_decrypt(hex2bin($encrypted_string), $cipher, $this->deskey, $options=OPENSSL_RAW_DATA, $iv); // 输出解密后的字符串
}
public function upOrderResponse($kami,$merchant_order_id,$orderResponse)
{
$orderService = OrderService::instance();
$response = json_decode($orderResponse,true);
$response['kami'] = $kami;
$data = ['response' => json_encode($response)];
$orderService->db()->where(array('merchant_order_id' => $merchant_order_id))->update($data);
}
}