This commit is contained in:
2024-08-08 00:26:29 +08:00
parent 9ab5393c45
commit b1ac5e95e0
18 changed files with 1286 additions and 127 deletions

View File

@@ -324,6 +324,103 @@
</div> </div>
<div class="api_hdrquestionnaireanswer_updateHdrquestionnaireanswer_response_result"></div> <div class="api_hdrquestionnaireanswer_updateHdrquestionnaireanswer_response_result"></div>
</div><div id="api_hdrquestionnaireanswer_del">
<div class="markdown_content">
***
```
/**
* desc 删除科室问卷答案
* authorwh
*
* 参数:
* id 数据id 必须
* api/Hdrquestionnaireanswer/del
* api/hdrquestionnaireanswer/del
*/
```
</div>
<div>
按需填写其它接口参数:
<textarea name="" id="api_hdrquestionnaireanswer_del_textarea" cols="100" rows="3">/api/hdrquestionnaireanswer/del</textarea>
<a href='JavaScript:;' onclick="DocObject.api_hdrquestionnaireanswer_del()">测试</a>
</div>
<div class="api_hdrquestionnaireanswer_del_response_result"></div>
</div><div id="api_hdrquestionnairequestion_addHdrquestionnairequestion">
<div class="markdown_content">
***
```
/**
* 新增科室问卷问题(一个问题对应多个答案)
*
* 参数:
* hdrdepartment_id 所属科室 所属科室 必须
* question 问卷问题 问卷问题 必须
* is_common 是否通用:yes=是,no=否 是否通用:yes=是,no=否 必须
* is_only_boy 只适合男:yes=是,no=否 只适合男:yes=是,no=否 必须
* is_only_girl 只适合女:yes=是,no=否 只适合女:yes=是,no=否 必须
* type 选项类型:one=单选,more=多选 选项类型:one=单选,more=多选 必须
* api/Hdrquestionnairequestion/addHdrquestionnairequestion
* api/hdrquestionnairequestion/addHdrquestionnairequestion
*/
```
</div>
<div>
按需填写其它接口参数:
<textarea name="" id="api_hdrquestionnairequestion_addHdrquestionnairequestion_textarea" cols="100" rows="3">/api/hdrquestionnairequestion/addHdrquestionnairequestion</textarea>
<a href='JavaScript:;' onclick="DocObject.api_hdrquestionnairequestion_addHdrquestionnairequestion()">测试</a>
</div>
<div class="api_hdrquestionnairequestion_addHdrquestionnairequestion_response_result"></div>
</div><div id="api_hdrquestionnairequestion_updateHdrquestionnairequestion">
<div class="markdown_content">
***
```
/**
* 修改科室问卷问题(一个问题对应多个答案)
* 参数:
* id ID ID 必须
* hdrdepartment_id 所属科室
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* api/Hdrquestionnairequestion/updateHdrquestionnairequestion
* api/hdrquestionnairequestion/updateHdrquestionnairequestion
*/
```
</div>
<div>
按需填写其它接口参数:
<textarea name="" id="api_hdrquestionnairequestion_updateHdrquestionnairequestion_textarea" cols="100" rows="3">/api/hdrquestionnairequestion/updateHdrquestionnairequestion</textarea>
<a href='JavaScript:;' onclick="DocObject.api_hdrquestionnairequestion_updateHdrquestionnairequestion()">测试</a>
</div>
<div class="api_hdrquestionnairequestion_updateHdrquestionnairequestion_response_result"></div>
</div><div id="api_hdrquestionnairequestion_del">
<div class="markdown_content">
***
```
/**
* desc 删除科室问卷问题(一个问题对应多个答案)
* authorwh
*
* 参数:
* id 数据id 必须
*
* api/Hdrquestionnairequestion/del
* api/hdrquestionnairequestion/del
*/
```
</div>
<div>
按需填写其它接口参数:
<textarea name="" id="api_hdrquestionnairequestion_del_textarea" cols="100" rows="3">/api/hdrquestionnairequestion/del</textarea>
<a href='JavaScript:;' onclick="DocObject.api_hdrquestionnairequestion_del()">测试</a>
</div>
<div class="api_hdrquestionnairequestion_del_response_result"></div>
</div><div id="api_hdrquestionnairequestion_getHdrquestionnairequestionList"> </div><div id="api_hdrquestionnairequestion_getHdrquestionnairequestionList">
<div class="markdown_content"> <div class="markdown_content">
*** ***
@@ -337,14 +434,9 @@
* 带分页 * 带分页
* current_page 当前页码 * current_page 当前页码
* list_rows 每页显示条数 默认15 * list_rows 每页显示条数 默认15
* question 问卷问题 * id ID
* id ID * hdrdepartment_id 所属科室
* hdrdepartment_id 所属科室 * question 问卷问题
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* *
* 所有字段说明<span style="color: gray">(可能有部分额外字段未在此体现)</span> * 所有字段说明<span style="color: gray">(可能有部分额外字段未在此体现)</span>
* id ID * id ID
@@ -369,58 +461,6 @@
</div> </div>
<div class="api_hdrquestionnairequestion_getHdrquestionnairequestionList_response_result"></div> <div class="api_hdrquestionnairequestion_getHdrquestionnairequestionList_response_result"></div>
</div><div id="api_hdrquestionnairequestion_addHdrquestionnairequestion">
<div class="markdown_content">
***
```
/**
* 新增科室问卷问题(一个问题对应多个答案)
*
* 参数:
* hdrdepartment_id 所属科室 所属科室 必须
* question 问卷问题 问卷问题 必须
* is_common 是否通用:yes=是,no=否 是否通用:yes=是,no=否 必须
* is_only_boy 只适合男:yes=是,no=否 只适合男:yes=是,no=否 必须
* is_only_girl 只适合女:yes=是,no=否 只适合女:yes=是,no=否 必须
* type 选项类型:one=单选,more=多选 选项类型:one=单选,more=多选 必须
* api/Hdrquestionnairequestion/addHdrquestionnairequestion
* api/hdrquestionnairequestion/addHdrquestionnairequestion
*/
```
</div>
<div>
按需填写其它接口参数:
<textarea name="" id="api_hdrquestionnairequestion_addHdrquestionnairequestion_textarea" cols="100" rows="3">/api/hdrquestionnairequestion/addHdrquestionnairequestion</textarea>
<a href='JavaScript:;' onclick="DocObject.api_hdrquestionnairequestion_addHdrquestionnairequestion()">测试</a>
</div>
<div class="api_hdrquestionnairequestion_addHdrquestionnairequestion_response_result"></div>
</div><div id="api_hdrquestionnairequestion_updateHdrquestionnairequestion">
<div class="markdown_content">
***
```
/**
* 修改科室问卷问题(一个问题对应多个答案)
* 参数:
* id ID ID 必须
* hdrdepartment_id 所属科室
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* api/Hdrquestionnairequestion/updateHdrquestionnairequestion
* api/hdrquestionnairequestion/updateHdrquestionnairequestion
*/
```
</div>
<div>
按需填写其它接口参数:
<textarea name="" id="api_hdrquestionnairequestion_updateHdrquestionnairequestion_textarea" cols="100" rows="3">/api/hdrquestionnairequestion/updateHdrquestionnairequestion</textarea>
<a href='JavaScript:;' onclick="DocObject.api_hdrquestionnairequestion_updateHdrquestionnairequestion()">测试</a>
</div>
<div class="api_hdrquestionnairequestion_updateHdrquestionnairequestion_response_result"></div>
</div><div id="api_hdrregister_addHdrregister"> </div><div id="api_hdrregister_addHdrregister">
<div class="markdown_content"> <div class="markdown_content">
*** ***
@@ -1322,11 +1362,11 @@
$('.api_hdrquestionnaireanswer_updateHdrquestionnaireanswer_response_result').html(JSON.stringify(res, null, "\t")); $('.api_hdrquestionnaireanswer_updateHdrquestionnaireanswer_response_result').html(JSON.stringify(res, null, "\t"));
$('.api_hdrquestionnaireanswer_updateHdrquestionnaireanswer_response_result').attr('style','color:green'); $('.api_hdrquestionnaireanswer_updateHdrquestionnaireanswer_response_result').attr('style','color:green');
},'json'); },'json');
}, api_hdrquestionnairequestion_getHdrquestionnairequestionList(){ }, api_hdrquestionnaireanswer_del(){
let url = $('#api_hdrquestionnairequestion_getHdrquestionnairequestionList_textarea').val(); let url = $('#api_hdrquestionnaireanswer_del_textarea').val();
$.post(url,{},function(res) { $.post(url,{},function(res) {
$('.api_hdrquestionnairequestion_getHdrquestionnairequestionList_response_result').html(JSON.stringify(res, null, "\t")); $('.api_hdrquestionnaireanswer_del_response_result').html(JSON.stringify(res, null, "\t"));
$('.api_hdrquestionnairequestion_getHdrquestionnairequestionList_response_result').attr('style','color:green'); $('.api_hdrquestionnaireanswer_del_response_result').attr('style','color:green');
},'json'); },'json');
}, api_hdrquestionnairequestion_addHdrquestionnairequestion(){ }, api_hdrquestionnairequestion_addHdrquestionnairequestion(){
let url = $('#api_hdrquestionnairequestion_addHdrquestionnairequestion_textarea').val(); let url = $('#api_hdrquestionnairequestion_addHdrquestionnairequestion_textarea').val();
@@ -1340,6 +1380,18 @@
$('.api_hdrquestionnairequestion_updateHdrquestionnairequestion_response_result').html(JSON.stringify(res, null, "\t")); $('.api_hdrquestionnairequestion_updateHdrquestionnairequestion_response_result').html(JSON.stringify(res, null, "\t"));
$('.api_hdrquestionnairequestion_updateHdrquestionnairequestion_response_result').attr('style','color:green'); $('.api_hdrquestionnairequestion_updateHdrquestionnairequestion_response_result').attr('style','color:green');
},'json'); },'json');
}, api_hdrquestionnairequestion_del(){
let url = $('#api_hdrquestionnairequestion_del_textarea').val();
$.post(url,{},function(res) {
$('.api_hdrquestionnairequestion_del_response_result').html(JSON.stringify(res, null, "\t"));
$('.api_hdrquestionnairequestion_del_response_result').attr('style','color:green');
},'json');
}, api_hdrquestionnairequestion_getHdrquestionnairequestionList(){
let url = $('#api_hdrquestionnairequestion_getHdrquestionnairequestionList_textarea').val();
$.post(url,{},function(res) {
$('.api_hdrquestionnairequestion_getHdrquestionnairequestionList_response_result').html(JSON.stringify(res, null, "\t"));
$('.api_hdrquestionnairequestion_getHdrquestionnairequestionList_response_result').attr('style','color:green');
},'json');
}, api_hdrregister_addHdrregister(){ }, api_hdrregister_addHdrregister(){
let url = $('#api_hdrregister_addHdrregister_textarea').val(); let url = $('#api_hdrregister_addHdrregister_textarea').val();
$.post(url,{},function(res) { $.post(url,{},function(res) {

View File

@@ -223,6 +223,67 @@
*/ */
``` ```
***
```
/**
* desc 删除科室问卷答案
* authorwh
*
* 参数:
* id 数据id 必须
* api/Hdrquestionnaireanswer/del
* api/hdrquestionnaireanswer/del
*/
```
***
```
/**
* 新增科室问卷问题(一个问题对应多个答案)
*
* 参数:
* hdrdepartment_id 所属科室 所属科室 必须
* question 问卷问题 问卷问题 必须
* is_common 是否通用:yes=是,no=否 是否通用:yes=是,no=否 必须
* is_only_boy 只适合男:yes=是,no=否 只适合男:yes=是,no=否 必须
* is_only_girl 只适合女:yes=是,no=否 只适合女:yes=是,no=否 必须
* type 选项类型:one=单选,more=多选 选项类型:one=单选,more=多选 必须
* api/Hdrquestionnairequestion/addHdrquestionnairequestion
* api/hdrquestionnairequestion/addHdrquestionnairequestion
*/
```
***
```
/**
* 修改科室问卷问题(一个问题对应多个答案)
* 参数:
* id ID ID 必须
* hdrdepartment_id 所属科室
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* api/Hdrquestionnairequestion/updateHdrquestionnairequestion
* api/hdrquestionnairequestion/updateHdrquestionnairequestion
*/
```
***
```
/**
* desc 删除科室问卷问题(一个问题对应多个答案)
* authorwh
*
* 参数:
* id 数据id 必须
*
* api/Hdrquestionnairequestion/del
* api/hdrquestionnairequestion/del
*/
```
*** ***
``` ```
/** /**
@@ -234,14 +295,9 @@
* 带分页 * 带分页
* current_page 当前页码 * current_page 当前页码
* list_rows 每页显示条数 默认15 * list_rows 每页显示条数 默认15
* question 问卷问题 * id ID
* id ID * hdrdepartment_id 所属科室
* hdrdepartment_id 所属科室 * question 问卷问题
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* *
* 所有字段说明<span style="color: gray">(可能有部分额外字段未在此体现)</span> * 所有字段说明<span style="color: gray">(可能有部分额外字段未在此体现)</span>
* id ID * id ID
@@ -259,40 +315,6 @@
*/ */
``` ```
***
```
/**
* 新增科室问卷问题(一个问题对应多个答案)
*
* 参数:
* hdrdepartment_id 所属科室 所属科室 必须
* question 问卷问题 问卷问题 必须
* is_common 是否通用:yes=是,no=否 是否通用:yes=是,no=否 必须
* is_only_boy 只适合男:yes=是,no=否 只适合男:yes=是,no=否 必须
* is_only_girl 只适合女:yes=是,no=否 只适合女:yes=是,no=否 必须
* type 选项类型:one=单选,more=多选 选项类型:one=单选,more=多选 必须
* api/Hdrquestionnairequestion/addHdrquestionnairequestion
* api/hdrquestionnairequestion/addHdrquestionnairequestion
*/
```
***
```
/**
* 修改科室问卷问题(一个问题对应多个答案)
* 参数:
* id ID ID 必须
* hdrdepartment_id 所属科室
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* api/Hdrquestionnairequestion/updateHdrquestionnairequestion
* api/hdrquestionnairequestion/updateHdrquestionnairequestion
*/
```
*** ***
``` ```
/** /**

View File

@@ -4,3 +4,4 @@
/.git /.git
/.idea /.idea
/composer.lock /composer.lock
.git*

View File

@@ -0,0 +1,121 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/27} {17:36}
*/
namespace wanghua\general_utility_tools_php\algorithm;
/**
* 常见算法
* Class AlgorithmTools
* @package wanghua\general_utility_tools_php\tool
*/
class Algorithm
{
/**
* desc权重随机选择算法
*
* 使用场景:转盘抽奖等需要指定概率的场景
*
* authorwh
* @param array $weights 权重数组 eg[1, 9, 30, 70] 概率的总和是100%
* return 返回计算后的索引
*/
static function weightRandom($weights){
//$weights = [1, 9, 30, 70]; // 权重数组
$totalWeight = array_sum($weights);
$min_num = min($weights);//取出数组中最小的值
$random = mt_rand($min_num, $totalWeight); // 生成一个最小元素到总权重的随机数
$cumulativeWeight = 0; // 累积权重
$selected = 0; // 选择的索引
foreach ($weights as $index => $weight) {
$cumulativeWeight += $weight; // 累加权重
if ($random <= $cumulativeWeight) {
$selected = $index; // 根据权重选择索引
break;
}
}
//输出选择的索引
return $selected;
}
/**
* desc测试权重随机算法概率
* authorwh
* @param array $weights 权重数组 eg[1, 9, 30, 70]
*/
static function testWeightRandom(array $weights){
echo json_encode($weights)."\n";
$trials = 1000; // 试验次数
$selectionCounts = array_fill(0, count($weights), 0); // 用于存储每个索引的选择次数
for ($i = 0; $i < $trials; $i++) {
$index = self::weightRandom($weights);
$selectionCounts[$index]++; // 记录选择次数
}
// 计算每个索引的选择概率
$probabilities = [];
foreach ($selectionCounts as $index => $count) {
$probabilities[$index] = ($count / $trials) * 100; // 转换为百分比
}
// 输出结果
echo "After {$trials} trials, the probabilities of selecting each index are:\n";
foreach ($probabilities as $index => $probability) {
echo "Index {$index}: {$probability}%\n";
}
}
/**
* desc洗牌算法
*
* 对数组进行随机排序,实现洗牌算法
* authorwh
* @param array $items eg: [1, 2, 3, 4, 5]
* @return array 返回计算后的数组
*/
static function shuffle(array $items) {
//$items = [1, 2, 3, 4, 5];
shuffle($items);
return $items;
}
/**
* 随机密码生成算法
*
* 作用:创建安全的随机密码,常用于用户注册或密码重置
* 使用场景:用户账户创建、密码重置链接生成
*/
static function randomPassword($length = 8) {
$password = '';
$possibleChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for ($i = 0; $i < $length; $i++) {
$password .= substr($possibleChars, mt_rand(0, strlen($possibleChars) - 1), 1);
}
return $password;
}
/**
* 随机颜色生成算法
*
* 作用生成随机RGB颜色值可用于网页设计中动态改变元素颜色
* 使用场景:动态网页背景、随机颜色显示的元素
*/
static function randomColor() {
$red = mt_rand(0, 255);
$green = mt_rand(0, 255);
$blue = mt_rand(0, 255);
return [$red, $green, $blue];
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/27} {17:36}
*/
namespace wanghua\general_utility_tools_php\algorithm;
/**
* 算法测试
* Class AlgorithmTest
* @package wanghua\general_utility_tools_php\algorithm
*/
class AlgorithmTest
{
/**
* desc测试权重随机算法概率
* authorwh
* @param array $weights 权重数组 eg[1, 9, 30, 70]
*/
static function testWeightRandom(array $weights){
echo json_encode($weights)."\n";
$trials = 1000; // 试验次数
$selectionCounts = array_fill(0, count($weights), 0); // 用于存储每个索引的选择次数
for ($i = 0; $i < $trials; $i++) {
$index = Algorithm::weightRandom($weights);
$selectionCounts[$index]++; // 记录选择次数
}
// 计算每个索引的选择概率
$probabilities = [];
foreach ($selectionCounts as $index => $count) {
$probabilities[$index] = ($count / $trials) * 100; // 转换为百分比
}
// 输出结果
echo "After {$trials} trials, the probabilities of selecting each index are:\n";
foreach ($probabilities as $index => $probability) {
echo "Index {$index}: {$probability}%\n";
}
}
}

View File

@@ -0,0 +1 @@
## 常见实用算法

View File

@@ -25,6 +25,7 @@ class AlibabaAuth
{ {
public $base_url = '';//不同业务线,授权地址不一样 public $base_url = '';//不同业务线,授权地址不一样
public $config = []; public $config = [];
public $request_body = [];
public function __construct($config) public function __construct($config)
{ {
$this->config = $config; $this->config = $config;
@@ -154,6 +155,7 @@ class AlibabaAuth
$url = $this->base_url.$urlPath.'?'.$request_params_str.'&access_token='.$accessToken.'&_aop_signature='.$_aop_signature; $url = $this->base_url.$urlPath.'?'.$request_params_str.'&access_token='.$accessToken.'&_aop_signature='.$_aop_signature;
//dump($url); //dump($url);
$this->request_body = $url;
$res = Curl::curl_post($url,[]); $res = Curl::curl_post($url,[]);
return $res; return $res;
} }

View File

@@ -133,6 +133,20 @@ class Testexample
$order->setGoods($goods,$order_info['buy_num']); $order->setGoods($goods,$order_info['buy_num']);
return $order->previewOrder(); return $order->previewOrder();
} }
//查询订单可以支持的支付渠道
function queryOrderPayChannel($order_id){
$config = config('meebo_supply_config');
$authObj = new AlibabaAuth($config);
$order = new StrictPay($authObj);
return $order->queryOrderPayChannel($order_id);
}
//组合收银台url获取
function getPayUrl(array $orderIds){
$config = config('meebo_supply_config');
$authObj = new AlibabaAuth($config);
$order = new StrictPay($authObj);
return $order->getPayUrl($orderIds,'PC');
}
//获取唤起旺旺聊天的链接 //获取唤起旺旺聊天的链接
function getCustomerServiceLink($toOpenUid){ function getCustomerServiceLink($toOpenUid){

View File

@@ -0,0 +1,127 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/6/29} {17:31}
*/
namespace app\index\controller;
use app\common\model\TabConf;
use app\index\logic\alibaba\distributes\notify\BaseStrictNotify;
use wanghua\general_utility_tools_php\alibaba\distributes\Testexample;
use app\index\logic\alibabanotify\ProductNotify;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
/**
* 阿里巴巴异步通知控制器类,是消息处理入口类
* Class Alibabanotify
* @package app\index\controller
*/
class Alibaba extends BasePublicController
{
/**
* desc通知
* index/Alibaba/notify
*
* 输出message
{
"data":{
"productIds":"107680826",
"msgSendTime":"2018-05-30 20:29:37",
"memberId":"shyxsscl",
"status":"RELATION_VIEW_PRODUCT_REPOST"
},
"gmtBorn":1720459935606,
"msgId":88837491757,
"type":"PRODUCT_RELATION_VIEW_PRODUCT_REPOST",
"userInfo":"b2b-1881150273"
}
* authorwh
* @return \think\response\Json
*/
function notify(){
return Mmodel::catchJson(function (){
Tools::log_to_write_txt(['执行消息处理']);
//根据消息类型,选择对应的处理类
$message_data = input('message');
if(empty($message_data)){
return Tools::set_fail('message为空');
}
$message_data = json_decode($message_data,true);
Tools::log_to_write_txt(['消息解码'=>$message_data]);
if(empty($message_data['type'])){
return Tools::set_fail('type为空');
}
//$key = strtolower(explode('_',$message_data['type'])[0]);
//获取消息类型
$fn = strtolower($message_data['type']);//类型即为方法名
//消息类型前缀即为类名
$class = '\\app\\index\\logic\\alibabanotify\\'.ucfirst(explode('_',$fn)[0]).'Notify';
//实例化类
return (new $class())->{$fn}($message_data);//调用方法
});
}
/**
* descali采购获取临时授权code
*
* index/alibaba/webAuthCode
*
* authorwh
* @return string
*/
function webAuthCode(){
$Testexample = new Testexample();
$res = $Testexample->testWebAuth(request()->domain().'/index/alibaba/webUserAuth');
return $res;
}
/**
* desc网页授权,code换取token
*
* index/alibaba/webUserAuth
*
* authorwh
*/
function webUserAuth(){
$code = input('code');
if(empty($code)){
return $this->error('授权失败');
}
$redirect_uri = url('test/test2');
$Testexample = new Testexample();
$res = $Testexample->getTokenByCode($code,$redirect_uri);
if($res['code'] != 200){
return $this->error('授权失败.'.$res['msg']);
}
$data = json_decode($res['data']);
$auth_data = [
'access_token'=>$data['access_token'],
'aliid'=>$data['aliId'],
'expires_in'=>$data['expires_in'],
'memberid'=>$data['memberId'],
'refresh_token'=>$data['refresh_token'],
'refresh_token_timeout'=>$data['refresh_token_timeout'],
'resource_owner'=>$data['resource_owner'],
];
//写入数据库
Mmodel::existsUpdateInsert(TabConf::$fa_alibaba_user_auth,['access_token'=>$data['access_token']],$auth_data);
return '授权成功';
}
//function getCode(){
// return Mmodel::catchJson(function (){
// //保存code
// $code = input('code');
//
// });
//}
}

View File

@@ -0,0 +1,18 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/25} {0:41}
*/
namespace app\index\logic\alibabanotify;
use app\index\logic\BaseLogic;
class BaseAlibabaLogic extends BaseLogic
{
//接收消息成功后只要响应http code是200,则认为消息消费成功
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/25} {1:04}
*/
namespace app\index\logic\alibabanotify;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
class LogisticsNotify extends BaseAlibabaLogic
{
/**
* 物流单状态变更(买家视角)
*/
function logistics_buyer_view_trace($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 物流单号修改消息
*/
function logistics_mail_no_change($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
}

View File

@@ -0,0 +1,137 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/25} {0:37}
*/
namespace app\index\logic\alibabanotify;
use app\index\logic\BaseLogic;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
class OrderNotify extends BaseAlibabaLogic
{
/**
* desc1688创建订单买家视角/order created (buyer view)
* authorwh
* @return array
*/
function order_buyer_view_buyer_make($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* desc1688交易成功卖家视角
* authorwh
*/
function order_buyer_view_order_success($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688订单批量支付状态同步消息
*/
function order_batch_pay($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688交易付款买家视角/1688 transaction payment (buyer view)
*/
function order_buyer_view_order_pay($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688卖家关闭订单买家视角/seller closing order (buyer view)
*/
function order_buyer_view_order_seller_close($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688修改订单价格买家视角/order price modification (buyer view)
*/
function order_buyer_view_order_price_modify($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688订单发货买家视角/1688 order delivery (buyer view)
*/
function order_buyer_view_announce_sendgoods($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688订单部分发货买家视角/Partial delivery of 1688 order (buyer view)
*/
function order_buyer_view_part_part_sendgoods($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 商家修改订单地址(买家视角)
*/
function order_buyer_view_order_seller_modify_adress($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688订单售中退款买家视角
*/
function order_buyer_view_order_buyer_refund_in_sales($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688订单售后退款买家视角
*/
function order_buyer_view_order_refund_after_sales($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688买家关闭订单买家视角/buyer closing order (buyer view)
*/
function order_buyer_view_order_buyer_close($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688订单确认收货买家视角/order receipt confirmation (buyer view)
*/
function order_buyer_view_order_comfirm_receivegoods($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/25} {1:06}
*/
namespace app\index\logic\alibabanotify;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
class ProductNotify extends BaseAlibabaLogic
{
/**
* 1688产品审核下架关系用户视角
*/
function product_relation_view_product_audit($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688产品删除关系用户视角
*/
function product_relation_view_product_delete($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688产品新增或修改关系用户视角
*/
function product_relation_view_product_new_or_modify($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688产品上架关系用户视角
*/
function product_relation_view_product_repost($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688商品库存变更消息关系用户视角
*/
function product_product_inventory_change($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 精选货源商品下架消息
*/
function product_pft_offer_quit($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 精选货源商品价格变动消息
*/
function product_pft_offer_price_modify($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
/**
* 1688产品下架关系用户视角
*/
function product_relation_view_product_expire($message_data){
return Mmodel::catch(function ()use($message_data){
Tools::log_to_write_txt([__FUNCTION__.'消息入参:'=>$message_data]);
});
}
}

View File

@@ -0,0 +1,18 @@
## 阿里巴巴开放平台消息通知模板
### 特别说明
#### Alibaba.php是控制器类复制可用是消息通道httpCallback的回调地址类文件。
##### eghttp://www.xxx.com/index/alibaba/notify
##### 回调地址配置入口https://open.1688.com/develop/app/detail?spm=a260s.develop-app-list.0.0.4d875bfaS5YzoD&appkey=7571564&appKey=7571564
进入页面后找到“日常消息测试”按钮,点击后在弹出的界面中进行配置。
### 文件说明
#### 按照消息类型前缀分类(复制可用)
1. 订单相关 OrderNotify.php
2. 产品相关 ProductNotify.php
3. 物流相关 LogisticsNotify.php
4. 售后相关
......以此类推,消息类型的小写就是类的方法名。
这里只是打个样,这几个模板可以直接复制,补充上自己的业务逻辑即可。

View File

@@ -26,7 +26,7 @@ class StrictOrder extends BaseStrict
//发票信息 //发票信息
private $invoice = []; private $invoice = [];
//交易类型 由于不同的商品支持的交易方式不同没有一种交易方式是全局通用的所以当前下单可使用的交易方式必须通过下单预览接口的tradeModeNameList获取。 //交易类型 由于不同的商品支持的交易方式不同没有一种交易方式是全局通用的所以当前下单可使用的交易方式必须通过下单预览接口的tradeModeNameList获取。
private $tradeType = ''; public $tradeType = '';
/** /**
* desc收货地址说明 * desc收货地址说明
@@ -68,10 +68,27 @@ class StrictOrder extends BaseStrict
function setGoods($goods,$buy_num){ function setGoods($goods,$buy_num){
$this->goods = [ $this->goods = [
'offerId'=>$goods['offerid'], 'offerId'=>$goods['offerid'],
'specId'=>$goods['specid'],//商品规格id
'quantity'=>$buy_num,//$goods['quantity'],//商品数量(计算金额用) 'quantity'=>$buy_num,//$goods['quantity'],//商品数量(计算金额用)
]; ];
if(!empty($goods['specid'])){
$this->goods['specId'] = $goods['specid'];//商品规格id
}
}
/**
* desc设置发票信息
* authorwh
*/
function setInvoice(array $invoice){
$this->invoice = $invoice;
}
/**
* desc设置发票信息
* authorwh
*/
function setInvoice(array $invoice){
$this->invoice = $invoice;
} }
/** /**
* desc创建分销订单 * desc创建分销订单
@@ -95,6 +112,8 @@ class StrictOrder extends BaseStrict
if(empty($this->tradeType)){ if(empty($this->tradeType)){
throw new Exception('交易类型必须'); throw new Exception('交易类型必须');
} }
//由于不同的商品支持的交易方式不同,没有一种交易方式是全局通用的,
//所以当前下单可使用的交易方式必须通过下单预览接口的tradeModeNameList获取。
$request_data = ['tradeType'=>$this->tradeType]; $request_data = ['tradeType'=>$this->tradeType];
//boutiquefenxiao(新分销严选) //boutiquefenxiao(新分销严选)
@@ -247,4 +266,153 @@ class StrictOrder extends BaseStrict
return $res; return $res;
} }
/**
* 订单列表查看(买家视角)
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.getBuyerOrderList-1&aopApiCategory=trade_new
*
*/
function getOrderList($queryParams=[],$page=1,$pageSize=20){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.getSellerOrderList/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['page'] = $page;
$request_data['pageSize'] = $pageSize;
//业务类型,支持: "cn"(普通订单类型), "ws"(大额批发订单类型), "yp"(普通拿样订单类型), "yf"(一分钱拿样订单类型),
// "fs"(倒批(限时折扣)订单类型), "cz"(加工定制订单类型), "ag"(协议采购订单类型), "hp"(伙拼订单类型),
// "gc"(国采订单类型), "supply"(供销订单类型), "nyg"(nyg订单类型), "factory"(淘工厂订单类型),
// "quick"(快订下单), "xiangpin"(享拼订单), "nest"(采购商城-鸟巢), "f2f"(当面付), "cyfw"(存样服务),
// "sp"(代销订单标记), "wg"(微供订单), "factorysamp"(淘工厂打样订单), "factorybig"(淘工厂大货订单)
if(isset($queryParams['bizTypes'])){
$request_data['bizTypes'] = $queryParams['bizTypes'];
}
//下单开始时间 20180802211113000+0800
if(isset($queryParams['createStartTime'])){
$request_data['createStartTime'] = $queryParams['createStartTime'];
}
//下单结束时间 20180802211113000+0800
if(isset($queryParams['createEndTime'])){
$request_data['createEndTime'] = $queryParams['createEndTime'];
}
//是否查询历史订单表,默认查询当前表即默认值为false
if(isset($queryParams['isHis'])){
$request_data['isHis'] = $queryParams['isHis'];
}
//查询修改时间结束 20180802211113000+0800
if(isset($queryParams['modifyStartTime'])){
$request_data['modifyStartTime'] = $queryParams['modifyStartTime'];
}
//查询修改时间结束 20180802211113000+0800
if(isset($queryParams['modifyEndTime'])){
$request_data['modifyEndTime'] = $queryParams['modifyEndTime'];
}
//订单状态,值有 success, cancel(交易取消,违约金等交割完毕), waitbuyerpay(等待卖家付款)
// waitsellersend(等待卖家发货),waitbuyerreceive(等待买家收货 )
if(isset($queryParams['orderStatus'])){
$request_data['orderStatus'] = $queryParams['orderStatus'];
}
//查询分页页码从1开始
//if(isset($queryParams['page'])){
// $request_data['page'] = $queryParams['page'];
//}
////查询的每页的数量 20
//if(isset($queryParams['pageSize'])){
// $request_data['pageSize'] = $queryParams['pageSize'];
//}
//退款状态,支持: "waitselleragree"(等待卖家同意), "refundsuccess"(退款成功), "refundclose"(退款关闭),
// "waitbuyermodify"(待买家修改), "waitbuyersend"(等待买家退货), "waitsellerreceive"(等待卖家确认收货)
if(isset($queryParams['refundStatus'])){
$request_data['refundStatus'] = $queryParams['refundStatus'];
}
//卖家memberId b2b-1624961198
if(isset($queryParams['sellerMemberId'])){
$request_data['sellerMemberId'] = $queryParams['sellerMemberId'];
}
//卖家loginId alitestforisv02
if(isset($queryParams['sellerLoginId'])){
$request_data['sellerLoginId'] = $queryParams['sellerLoginId'];
}
//卖家评价状态 (4:已评价,5:未评价,6;不需要评价)
if(isset($queryParams['sellerRateStatus'])){
$request_data['sellerRateStatus'] = $queryParams['sellerRateStatus'];
}
//交易类型: 担保交易(1), 预存款交易(2), ETC境外收单交易(3), 即时到帐交易(4), 保障金安全交易(5), 统一交易流程(6),
// 分阶段交易(7), 货到付款交易(8), 信用凭证支付交易(9), 账期支付交易(10), 1688交易4.0,新分阶段交易(50060),
// 当面付的交易流程(50070), 服务类的交易流程(50080)
if(isset($queryParams['tradeType'])){
$request_data['tradeType'] = $queryParams['tradeType'];
}
//商品名称
if(isset($queryParams['productName'])){
$request_data['productName'] = $queryParams['productName'];
}
//是否需要查询买家的详细地址信息和电话 false
if(isset($queryParams['needBuyerAddressAndPhone'])){
$request_data['needBuyerAddressAndPhone'] = $queryParams['needBuyerAddressAndPhone'];
}
//是否需要查询备注信息 false
if(isset($queryParams['needMemoInfo'])){
$request_data['needMemoInfo'] = $queryParams['needMemoInfo'];
}
//外部订单号,可用于控制幂等 90187872898371
if(isset($queryParams['outOrderId'])){
$request_data['outOrderId'] = $queryParams['outOrderId'];
}
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* 订单详情查看(买家视角)
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.get.buyerView-1&aopApiCategory=trade_new
*/
function getBuyerView(int $orderId,$webSite='1688',$includeFields='',$attributeKeys='',$outOrderId=''){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.get.buyerView/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['orderId'] = $orderId;//交易的订单id 1234345
$request_data['webSite'] = $webSite;//站点信息指定调用的API是属于国际站alibaba还是1688网站1688
$request_data['includeFields'] = $includeFields;//查询结果中包含的域GuaranteesTerms保障条款NativeLogistics物流信息RateDetail评价详情OrderInvoice发票信息。默认返回GuaranteesTerms、NativeLogistics、OrderInvoice。
$request_data['attributeKeys'] = $attributeKeys;//垂直表中的attributeKeys
$request_data['outOrderId'] = $outOrderId;//外部订单id控制幂等
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* 获取交易订单的物流信息(买家视角)
*
* 该接口需要获得订单买家的授权,获取买家的订单的物流详情,在采购或者分销场景中,作为买家也有获取物流详情的需求。
* 该接口能查能根据订单号查看物流详情,包括发件人,收件人,所发货物明细等。由于物流单录入的原因,
* 可能跟踪信息的API查询会有延迟。该API需要向开放平台申请权限才能访问。
*
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.logistics:alibaba.trade.getLogisticsInfos.buyerView-1&aopApiCategory=Logistics_NEW
*/
function getLogisticsInfosBuyerView(int $orderId,$webSite='1688',$fields=''){
$urlPath = "param2/1/com.alibaba.logistics/alibaba.trade.getLogisticsInfos.buyerView/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['orderId'] = $orderId;//交易的订单id 1234345
$request_data['webSite'] = $webSite;//站点信息指定调用的API是属于国际站是1688业务还是icbu业务 (1688或者alibaba)
$request_data['fields'] = $fields;//需要返回的字段,目前有:company.name,sender,receiver,sendgood。返回的字段要用英文逗号分隔开
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* 获取交易订单的物流跟踪信息(买家视角)
*
* 该接口需要获取订单买家的授权,获取买家的订单的物流跟踪信息,在采购或者分销场景中,作为买家也有获取物流详情的需求。
* 该接口能查能根据物流单号查看物流单跟踪信息。由于物流单录入的原因可能跟踪信息的API查询会有延迟。
* 该API需要向开放平台申请权限才能访问。
*
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.logistics:alibaba.trade.getLogisticsTraceInfo.buyerView-1&aopApiCategory=Logistics_NEW
*/
function getLogisticsTraceInfoBuyerView(int $orderId,$webSite='1688',$logisticsId=''){
$urlPath = "param2/1/com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['orderId'] = $orderId;//交易的订单id 1234345
$request_data['webSite'] = $webSite;//站点信息指定调用的API是属于国际站是1688业务还是ic
$request_data['logisticsId'] = $logisticsId;//该订单下的物流编号 AL8234243
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
} }

View File

@@ -30,4 +30,34 @@ class StrictPay extends BaseStrict
$res = $this->authObj->request($urlPath, $request_data); $res = $this->authObj->request($urlPath, $request_data);
return $res; return $res;
} }
/**
* desc查询订单可以支持的支付渠道
* authorwh
* @param string $order_id
*/
function queryOrderPayChannel(string $order_id){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.payWay.query/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['orderId'] = $order_id;
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* desc组合收银台url获取
* authorwh
* @param string $orderIds 订单列表 格式参考 字符串格式的数组:["123456789","123456789"]
* @param string $payPlatformType PC或WIRELESS
* @return mixed
*/
function getPayUrl(string $orderIds,string $payPlatformType){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.grouppay.url.get/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['orderIds'] = $orderIds;//json_encode($orderIds);
$request_data['payPlatformType'] = $payPlatformType;//PC或WIRELESS
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
} }

View File

@@ -0,0 +1,227 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/23} {22:57}
*/
namespace wanghua\general_utility_tools_php\alibaba\distributes\strict;
use wanghua\general_utility_tools_php\alibaba\distributes\BaseStrict;
use wanghua\general_utility_tools_php\tool\Tools;
class StrictRefund extends BaseStrict
{
/**
* 创建退款退货申请
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.createRefund-1
*/
function createRefund($params){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.createRefund/".$this->authObj->config['appkey'];
$request_data = [];
//主订单
if(empty($params['orderId'])){
return Tools::set_fail('orderId不能为空');
}
$request_data['orderId'] = $params['orderId'];
//子订单 订单接口 productItems- subItemID 就是子订单ID
// 卖家拒绝退款后无法重新申请需要到1688后台退款单页面 修改退款协议
if(empty($params['orderEntryIds'])){
return Tools::set_fail('orderEntryIds不能为空');
}
$request_data['orderEntryIds'] = $params['orderEntryIds'];
//退款/退款退货。只有已收到货,才可以选择退款退货 退款:"refund"; 退款退货:"returnRefund"
if(empty($params['disputeRequest'])){
return Tools::set_fail('disputeRequest不能为空');
}
$request_data['disputeRequest'] = $params['disputeRequest'];
//退款金额(单位:分)。不大于实际付款金额;等待卖家发货时,必须为商品的实际付款金额。
if(empty($params['applyPayment'])){
return Tools::set_fail('applyPayment不能为空');
}
$request_data['applyPayment'] = $params['applyPayment'];
//退运费金额(单位:分)。
if(empty($params['applyCarriage'])){
return Tools::set_fail('applyCarriage不能为空');
}
$request_data['applyCarriage'] = $params['applyCarriage'];
//退款原因id从API getRefundReasonList获取
if(empty($params['applyReasonId'])){
return Tools::set_fail('applyReasonId不能为空');
}
$request_data['applyReasonId'] = $params['applyReasonId'];
//退款申请理由2-150字
if(empty($params['description'])){
return Tools::set_fail('description不能为空');
}
$request_data['description'] = $params['description'];
//货物状态 售中等待卖家发货:"refundWaitSellerSend"; 售中等待买家收货:"refundWaitBuyerReceive";
// 售中已收货(未确认完成交易):"refundBuyerReceived" 售后未收货:"aftersaleBuyerNotReceived";
// 售后已收到货:"aftersaleBuyerReceived"
if(empty($params['goodsStatus'])){
return Tools::set_fail('goodsStatus不能为空');
}
$request_data['goodsStatus'] = $params['goodsStatus'];
//凭证图片URLs。1-5张必须使用API uploadRefundVoucher返回的“图片域名/相对路径”
if(isset($params['vouchers'])){
$request_data['vouchers'] = $params['vouchers'];
}
//子订单退款数量。仅在售中买家已收货(退款退货)时,可指定退货数量;默认,全部退货。[{"id":586683458996743215,"count":1}]
if(isset($params['orderEntryCountList'])){
$request_data['orderEntryCountList'] = $params['orderEntryCountList'];
}
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* 查询退款退货原因(用于创建退款退货)
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.getRefundReasonList-1
*/
function getRefundReasonList(int $orderId,$orderEntryIds,$goodsStatus){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.getRefundReasonList/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['orderId'] = $orderId;//主订单id 1234345
$request_data['orderEntryIds'] = $orderEntryIds;//子订单id Long[]
//售中等待买家发货:”refundWaitSellerSend"; 售中等待买家收货:"refundWaitBuyerReceive";
// 售中已收货(未确认完成交易):"refundBuyerReceived" 售后未收货:"aftersaleBuyerNotReceived";
// 售后已收到货:"aftersaleBuyerReceived"
$request_data['goodsStatus'] = $goodsStatus;//货物状态
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* @deprecated 【可在前端通过表单提交】
*
* 上传退款退货凭证
*
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.uploadRefundVoucher-1
*/
function uploadRefundVoucher($imageData){
//$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.uploadRefundVoucher/".$this->authObj->config['appkey'];
//$request_data = [];
//$request_data['imageData'] = $imageData;//凭证图片数据。小于1Mjpg格式。
//$res = $this->authObj->request($urlPath, $request_data);
//return $res;
}
/**
* 查询退款单列表(买家视角)
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.refund.buyer.queryOrderRefundList-1&aopApiCategory=trade_new
* 买家查看退款单列表,该接口不支持子账号查询,请使用主账号授权后查询
*/
function queryOrderRefundList($params){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.refund.buyer.queryOrderRefundList/".$this->authObj->config['appkey'];
$request_data = [];
//订单Id
if(isset($params['orderId'])){
$request_data['orderId'] = $params['orderId'];
}
//退款申请时间(起始) 20220926114526000+0800
if(isset($params['applyStartTime'])){
$request_data['applyStartTime'] = $params['applyStartTime'];
}
//退款申请时间(截止) 20220926114526000+0800
if(isset($params['applyEndTime'])){
$request_data['applyEndTime'] = $params['applyEndTime'];
}
//退款状态列表 等待卖家同意 waitselleragree;退款成功 refundsuccess;退款关闭 refundclose;
//待买家修改 waitbuyermodify;等待买家退货 waitbuyersend;等待卖家确认收货 waitsellerreceive
if(isset($params['refundStatusSet'])){
$request_data['refundStatusSet'] = $params['refundStatusSet'];
}
//卖家memberId
if(isset($params['sellerMemberId'])){
$request_data['sellerMemberId'] = $params['sellerMemberId'];
}
//当前页码
if(isset($params['currentPageNum'])){
$request_data['currentPageNum'] = $params['currentPageNum'];
}
//每页条数
if(isset($params['pageSize'])){
$request_data['pageSize'] = $params['pageSize'];
}
//退货物流单号传此字段查询时需同时传入sellerMemberId
if(isset($params['logisticsNo'])){
$request_data['logisticsNo'] = $params['logisticsNo'];
if(empty($params['sellerMemberId'])){
return Tools::set_fail('logisticsNo必须与sellerMemberId同时传入');
}
}
//退款修改时间(起始) 20220926114526000+0800
if(isset($params['modifyStartTime'])){
$request_data['modifyStartTime'] = $params['modifyStartTime'];
}
//退款修改时间(截止) 20220926114526000+0800
if(isset($params['modifyEndTime'])){
$request_data['modifyEndTime'] = $params['modifyEndTime'];
}
//1:售中退款2:售后退款0:所有退款单
if(isset($params['dipsuteType'])){
$request_data['dipsuteType'] = $params['dipsuteType'];
}
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* 查询退款单详情-根据订单ID买家视角
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.refund.OpQueryBatchRefundByOrderIdAndStatus-1&aopApiCategory=trade_new
*/
function queryBatchRefundByOrderIdAndStatus(int $orderId,string $queryType){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.refund.OpQueryBatchRefundByOrderIdAndStatus/".$this->authObj->config['appkey'];
$request_data = [];
//订单Id
$request_data['orderId'] = $orderId;
//查询类型 1活动3:退款成功(只支持退款中和退款成功)
$request_data['queryType'] = $queryType;
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* 退款单操作记录列表(买家视角)
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.refund.OpQueryOrderRefundOperationList-1
*/
function queryOrderRefundOperationList(string $refundId,$pageNo=1,$pageSize=100){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.refund.OpQueryOrderRefundOperationList/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['refundId'] = $refundId;
$request_data['pageNo'] = $pageNo;
$request_data['pageSize'] = $pageSize;
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
/**
* 买家提交退款货信息
* https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.trade:alibaba.trade.refund.returnGoods-1
*/
function buyerSubmitRefundGoodsInfo(string $refundId,string $logisticsCompanyNo,string $freightBill,string $description='',string $vouchers=''){
$urlPath = "param2/1/com.alibaba.trade/alibaba.trade.refund.returnGoods/".$this->authObj->config['appkey'];
$request_data = [];
$request_data['refundId'] = $refundId;
$request_data['logisticsCompanyNo'] = $logisticsCompanyNo;
$request_data['freightBill'] = $freightBill;
if($description){
$request_data['description'] = $description;//发货说明内容在2-200个字之间
}
//凭证图片URLs必须使用API alibaba.trade.uploadRefundVoucher返回的“图片域名/相对路径”,
//最多可上传 10 张图片 单张大小不超过1M支持jpg、gif、jpeg、png、和bmp格式。
// 请上传凭证,以便以后续赔所需(不上传将无法理赔)
if($vouchers){
$request_data['vouchers'] = $vouchers;//[https://cbu01.alicdn.com/img/ibank/2019/901/930/11848039109.jpg]
}
$res = $this->authObj->request($urlPath, $request_data);
return $res;
}
}

View File

@@ -80,7 +80,6 @@ class Ip
* @return bool * @return bool
*/ */
function qihuBaidu($ip){ function qihuBaidu($ip){
$url = 'https://qifu.baidu.com/ip/geo/v1/district?ip='.$ip;
if($this->isPrivateIP($ip)){ if($this->isPrivateIP($ip)){
return true;//国内 return true;//国内
} }
@@ -92,21 +91,24 @@ class Ip
if($this->getRecord($ip)){ if($this->getRecord($ip)){
return false; return false;
} }
$res = Curl::curl_get($url);
$res = $this->curl_get($ip);
if($res['code'] == 200){//请求成功 if($res['code'] == 200){//请求成功
if(empty($res['data'])){ if(empty($res['data'])){
Tools::log_to_write_txt(['error'=>'IP查询,curl结果为空','$res'=>$res,'$url'=>$url]); Tools::log_to_write_txt(['error'=>'IP查询,curl结果为空','$res'=>$res]);
} }
//校验ip属地 //校验ip属地
$data = json_decode($res['data'],true); $data = json_decode($res['data'],true);
if($data['code'] != 'Success'){//查询失败 if($data['code'] != 'Success'){//查询失败
Tools::log_to_write_txt(['error'=>'IP查询成功但结果返回为失败.','$res'=>$res,'$url'=>$url]); Tools::log_to_write_txt(['error'=>'IP查询成功但结果返回为失败.','$res'=>$res]);
return true; return true;
} }
//查询成功 //查询成功
if(empty($data['data']['country'])){ if(empty($data['data']['country'])){
//country为空时默认为国内 //country为空时默认为国内
Tools::log_to_write_txt(['error'=>'IP查询成功但country返回为空.','$res'=>$res,'$url'=>$url]); Tools::log_to_write_txt(['error'=>'IP查询成功但country返回为空.','$res'=>$res]);
return true; return true;
} }
if($data['data']['country'] == '中国'){ if($data['data']['country'] == '中国'){
@@ -117,11 +119,11 @@ class Ip
$this->insertRecord($ip,$data['data']['continent'].' '.$data['data']['prov'],$data['data']['country'],'no'); $this->insertRecord($ip,$data['data']['continent'].' '.$data['data']['prov'],$data['data']['country'],'no');
//缓存ip地址 //缓存ip地址
cache($ip,'no');//国外 cache($ip,'no');//国外
Tools::log_to_write_txt(['ip地址不在中国内禁止访问:'.$ip,'curl data'=>$res['data'],'$url'=>$url]); Tools::log_to_write_txt(['ip地址不在中国内禁止访问:'.$ip,'curl data'=>$res['data']]);
//return redirect($this->redirect_url); //return redirect($this->redirect_url);
return false; return false;
} }
Tools::log_to_write_txt(['error'=>'IP查询,curl请求失败.','$res'=>$res,'$url'=>$url]); Tools::log_to_write_txt(['error'=>'IP查询,curl请求失败.','$res'=>$res]);
return true; return true;
} }
/** /**
@@ -188,17 +190,17 @@ class Ip
/** /**
CREATE TABLE `fa_ip_attack_record` ( CREATE TABLE `fa_ip_attack_record` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`ip` varchar(30) NOT NULL DEFAULT '' COMMENT 'IP', `ip` varchar(30) NOT NULL DEFAULT '' COMMENT 'IP',
`territory` varchar(50) DEFAULT '' COMMENT '归属地', `territory` varchar(50) DEFAULT '' COMMENT '归属地',
`country` varchar(15) DEFAULT '' COMMENT '国家', `country` varchar(15) DEFAULT '' COMMENT '国家',
`is_china` varchar(10) NOT NULL DEFAULT '' COMMENT '是否中国', `is_china` varchar(10) NOT NULL DEFAULT '' COMMENT '是否中国',
`url` text NOT NULL COMMENT '带域名查询参数', `url` text NOT NULL COMMENT '带域名查询参数',
`params` text COMMENT '参数', `params` text COMMENT '参数',
`header` text COMMENT '请求头', `header` text COMMENT '请求头',
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '攻击时间', `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '攻击时间',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
KEY `index_ip` (`ip`) USING BTREE KEY `index_ip` (`ip`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='IP攻击记录'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='IP攻击记录';
*/ */
@@ -226,4 +228,47 @@ class Ip
->field('id,is_china') ->field('id,is_china')
->find(); ->find();
} }
/**
* desccurl
* authorwh
* @param $ip
* @return array
*/
function curl_get($ip){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://qifu.baidu.com/ip/geo/v1/district?ip='.$ip,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => 'CURL_HTTP_VERSION_1_1',
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'User-Agent: Apifox/1.0.0 (https://apifox.com)',
'Accept: */*',
'Host: qifu.baidu.com',
'Connection: keep-alive'
),
));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = curl_exec($curl);
// 显示错误信息
if (curl_error($curl)) {
//print "Error: ".curl_errno($curl).'-' . curl_error($curl);
//返回错误码
return ['code' => curl_errno($curl), 'msg' => curl_error($curl)];
} else {
//关闭句柄
curl_close($curl);
// 返回的内容
return ['code' => 200, 'msg' => 'cURL ok', 'data' => $data];
}
}
} }