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

288 lines
8.3 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;
#模板
class Piaopiaojb extends Core
{
protected $host = ''; // 主机,不设置,后台
protected $mid = ''; // 商户id
protected $token = ''; // 密钥
protected $api = '';
//漂漂金币砖石
public function piapiaojinbi_zs($param){
$check = array
(
'account' => 'userId',
'cash'=>'money',
'currencyType'=>'currencyType'
);
$this->api='cooperator/order/create';
$param['currencyType'] = 1;
return $this->submit($param, $check);
}
//漂漂金币砖石
public function piapiaojinbi_pb($param){
$check = array
(
'account' => 'userId',
'cash'=>'money',
'currencyType'=>'currencyType'
);
$this->api='cooperator/order/create';
$param['currencyType'] =2;
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$result = array();
$result['cash'] = 1;
$result['status'] = 4;
#以上基本不要变
if(isset($data['query_status'])){
if ($data['query_status'] == 1) {
$result['status'] = 2;
} else if($data['query_status'] == 3) {
$result['status'] = 3;
}else {
$result['status'] = 4;
}
}
#以下处理逻辑可以自由
$result['yes'] = 'ok'; //响应给上游的数据
$result['data'] = $data;
return $result;
}
public function query($order){
$request['cooperatorId'] = $this->mid;
$request['orderId'] = $order['order_id'];
$request['startTime'] = date('Y-m-d H:i:s', strtotime($order['create_at']) - 120); // 开始时间往前2
$request['endTime'] = date('Y-m-d H:i:s');
$request['pageNum'] = 1;
$request['pageSize'] = 10;
$url = $this->host . 'cooperator/order/list';
$response = $this->curl('get', $url, $request);
#记录日志
$log['type'] = 'query_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
#记录借宿
$array = $this->json_decode($response);
if(!$array|| !is_array($array)){
$result['status'] = 4;
return $result;
}
$result = $array;
$result['status'] = 4;
// var_dump($array);die;
if ($array['code']=='1' || $array['code']=='200' ) {
$data=$array['data'][0]??null;
if(!$data ){
return $result;
}
if($data['orderId'] == $order['order_id']){
if($data['state'] =='1'){
$result['query_status'] = 1;
$result['status'] = 2;
}elseif ($array['state'] == '0'){
$result['query_status'] = 0;
$result['status'] = 4;
}else{
$result['query_status'] = 3;
$result['status'] = 3;
}
}else{
foreach ($array['data'] as $key=>$value){
if($value['orderId'] == $order['order_id']){
if($value['state'] =='1'){
$result['query_status'] = 1;
$result['status'] = 2;
}elseif ($value['state'] == '0'){
$result['query_status'] = 0;
$result['status'] = 4;
}else{
$result['query_status'] = 3;
$result['status'] = 3;
}
continue;
}
}
}
}
return $result;
}
# 数据响应格式处理
public function response($data)
{
$log['type'] = 'response';
$log['data'] = $data;
$log['config'] = $this->data;
$this->log($log);
#以上不要做任何变动
// var_dump($data);die;
$array = $this->json_decode($data); //响应数据为json
#如果响应为XML格式
// $array = (array) simplexml_load_string($data);
if (!$array) {
$msg = 'error';
} elseif (isset($array['code']) && $array['code']=='1') { //修改判断逻辑为确定提交成功即可
# 正确
$msg = 'ok';
#如有其他判断以下
} else {
# 错误
$msg = $array['msg'] ?? 'error'; //前面message根据响应内容改成对应的错误提示
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询余额接口
public function account($day)
{
// $request['customer_id'] = $this->mid;
// $request['timestamp']=time();
// $request['sign'] = $this->_sign($request);
// $url = $this->host . 'api/customer';
// $response = $this->curl('post', $url, $request);
// $response = $this->response($response);
//
// $datas = $response['array']['data'];
// if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){
// $datas['account'] = $datas['balance']; //此处为余额
// }
//
// 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_data = $param['detail']; //上面替换剩下的
#结束初步
$request_data['cooperatorId']=$this->mid;
$request_data['orderId']=$param['order']; //我方系统订单号
$request_data['createTime']=date('Y-m-d H:i:s');
$request_data['origin']=1;
$request['cooperatorId']=$this->mid;
// $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// $charactersLength = strlen($characters);
// $randomString = '';
//
// for ($i = 0; $i < 16; $i++) {
// $randomString .= $characters[random_int(0, $charactersLength - 1)];
// }
//
// $aesKey = $randomString;
// var_dump($aesKey);
$aesKey = 'obdziR83TSFV06Re';
// 将订单ID转换为JSON字符串并进行AES加密
$data = json_encode($request_data);
$encryptedData = $this->aesEncrypt($data, $aesKey);
// 创建发送的数据结构
$request['requestData'] =$encryptedData;
$request['encrypted'] = $this->token;
$url = $this->host . $this->api; //组装地址
#该系统提交写法:
$response =$this->curl('post', $url, $request,true); //为post请求,json提交
#只需保留一个方法
$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'];
}
// AES 加密函数
public function aesEncrypt($plaintext, $key) {
// 使用 AES-128-ECB 模式进行加密不使用IV因为ECB模式不需要
$encrypted = openssl_encrypt(
$plaintext,
'aes-128-ecb',
$key,
);
// 返回 Base64 编码的密文
// return base64_encode($encrypted);
return $encrypted;
// return $iv.$ciphertext; // IV 需要和密文一起传输给解密方
}
// RSA 加密函数
public function rsaEncrypt($plaintext, $publicKeyPem) {
// $publicKeyPem = str_replace(["\r", "\n", ' '], '', $publicKeyPem);
// 公钥字符串(请替换为实际的公钥字符串)
// 获取当前文件的目录路径
$publicKey = openssl_pkey_get_public($this->channel['describe']);
openssl_public_encrypt($plaintext, $encrypted, $publicKey, OPENSSL_PKCS1_PADDING);
return $encrypted;
// return $encrypted;
}
}