Просмотр исходного кода

feat(api): 集成1688分销严选采购解决方案

- 添加1688分销商品列表、商品详情、订单预览等功能接口
- 集成支付宝支付回调处理逻辑
- 新增共富推荐配置查询功能,支持直推奖和分享奖比例计算
- 集成微信小程序数据解密功能
- 实现168订单退款申请及状态同步机制
- 添加完整的1688 API调用示例代码
- 配置1688代理服务相关依赖注入
shichen месяцев назад: 2
Родитель
Сommit
0a3b3c56d3
1 измененных файлов с 406 добавлено и 168 удалено
  1. 406 168
      app/controller/api/Test.php

+ 406 - 168
app/controller/api/Test.php

@@ -2,212 +2,450 @@
2 2
 
3 3
 namespace app\controller\api;
4 4
 
5
-use app\common\dao\shared\SharedProsperityUserDao;
6 5
 use app\common\enum\CommonEnum;
7
-use app\common\enum\shared\SharedProsperityRewardRecordEnum;
8
-use app\common\model\shared\SharedProsperityUser;
6
+use app\common\repositories\merchant\order\OrderMerchantRepository;
9 7
 use app\common\repositories\shared\SharedProsperityRecommendConfigRepository;
10
-use app\common\repositories\shared\SharedProsperityUserRepository;
11
-use app\common\repositories\store\order\StoreGroupOrderRepository;
12
-use app\common\repositories\store\order\StoreOrderRepository;
13 8
 use app\common\repositories\user\UserRepository;
14
-use app\common\repositories\user\UserSignXfbRepository;
15
-use app\traits\GzcApiRequest;
9
+use app\services\ThirdParty\AlibabaAgent\OrderService;
10
+use app\services\ThirdParty\AlibabaAgent\ProductService;
11
+use applet\WXBizDataCrypt;
16 12
 use think\facade\Db;
17 13
 
14
+/**
15
+ * 1688分销严选采购解决方案 - 接口调用示例
16
+ *
17
+ * 使用前请确保 config/third_party.php 中已配置 alibaba_agent 项:
18
+ *   'alibaba_agent' => [
19
+ *       'appKey'    => '你的AppKey',
20
+ *       'appSecret' => '你的AppSecret',
21
+ *       'gatewayUrl' => 'https://gw.open.1688.com/openapi/',
22
+ *   ]
23
+ *
24
+ * access_token 通过 OAuth 2.0 授权获取,或由用户提供。
25
+ */
18 26
 class Test
19 27
 {
28
+
29
+    /**
30
+     * 1688分销商品列表 - 调用示例
31
+     *
32
+     * API: com.alibaba.fenxiao:jxhy.product.getPageList-1
33
+     * 文档: https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.fenxiao%3Ajxhy.product.getPageList-1
34
+     */
20 35
     public function test()
21 36
     {
22
-        /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
23
-        $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
24
-        $groupOrderId = '11135';
25
-        $res = $storeGroupOrderRepository->storeGroupOrderPaySuccess($groupOrderId);
37
+
38
+        $json = [
39
+            'created_time' => '1775884033',
40
+            'data' => [
41
+                'app_id' => 'app_44108546-d27a-48ee-88c1-84b45b75114f',
42
+                'business_mode' => '00',
43
+                'created_time' => '20260411130713',
44
+                'description' => '',
45
+                'end_time' => '20260411130724',
46
+                'expend' => [
47
+                    'buyer_logon_id' => '131****9459',
48
+                    'cashPayAmt' => '298.00',
49
+                    'open_id' => '2088702188085230',
50
+                    'sub_open_id' => '2088702188085230',
51
+                ],
52
+                'fee_amt' => '1.13',
53
+                'id' => '002212026041113071210888906215589441536',
54
+                'order_no' => 'ALI177588403255323243_466',
55
+                'out_trans_id' => '2026041123001485231459472633',
56
+                'party_order_id' => '02232604114723298914940',
57
+                'pay_amt' => '298.00',
58
+                'pay_channel' => 'alipay_pub',
59
+                'real_amt' => '298.00',
60
+                'status' => 'succeeded',
61
+                'trans_response_add_info' => [
62
+                    'fund_bill_list' => [
63
+                        [
64
+                            'amount' => '298.00',
65
+                            'fund_channel' => 'ALIPAYACCOUNT',
66
+                        ],
67
+                    ],
68
+                ],
69
+            ],
70
+            'prod_mode' => 'true',
71
+            'sign' => 'fgbSc95NQDor1/jH3/L0G55l3XB7wl+sDt45Mtig/8eSvLIVo0uoyyD+jWaLkXV5xY2iAV3w8W4tiyVUcMQwVvwDIt9zQ44HTo05ng0e6CHCXLxFQbg/SHsjmK/3hin/2t6HkEjlitJYVikcPxMA0vnlR+lL/xMOYqNMDuq9oQQ=',
72
+            'id' => '002210888906265044500480',
73
+            'type' => 'HF',
74
+            'app_id' => 'app_44108546-d27a-48ee-88c1-84b45b75114f',
75
+            'object' => 'payment',
76
+        ];
77
+
78
+        /** @var OrderMerchantRepository $orderMerchantRepository */
79
+        $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
80
+        $res = $orderMerchantRepository->doNotifyHF($json['data']);
81
+
26 82
         dd($res);
27 83
 
84
+        die;
85
+
86
+        $orderService = new OrderService();
87
+        //
88
+        //
89
+        // $orderId = '3298535043727138963';
90
+        // $payRes = $orderService->prepareProtocolPay(['orderId'=>$orderId]);
91
+        // dd($payRes);
92
+
93
+        $cargoParamList = '{"offerId":"1045816431082","specId":"2fc39c573acfab640d10bcb1b533f041","quantity":1}';
94
+        $addressParam = '{"fullName":"测试","mobile":"17756507016","provinceText":"河北省","cityText":"廊坊市","areaText":"三河市","address":"兴远高科产业园23号楼2层210"}';
95
+
96
+
97
+        $cargoParamList = json_decode($cargoParamList,true);
98
+        $addressParam = json_decode($addressParam,true);
99
+        $flow = 'general';
28 100
 
29
-        /** @var UserSignXfbRepository $xfbRepository */
30
-        $xfbRepository = app()->make(UserSignXfbRepository::class);
31
-        // 结算
32
-        $res = $xfbRepository->settlement(['wx177572166462040882']);
101
+        $res = $orderService->previewOrder(['cargoParamList' => $cargoParamList, 'addressParam' => $addressParam,'flow'=>$flow]);
33 102
         dd($res);
34 103
 
35 104
 
36 105
 
37 106
 
38 107
 
39
-        $a = bcmul(99, CommonEnum::ORDER_EARNING_ALLOCATION['WonderfulLiving']['Lock']['BrokeragePrice']['Ratio']['code'], CommonEnum::CALCULATE_THE_NUMBER_OF_DECIMAL_PLACES);
40
-        $b = bcmul(198, CommonEnum::ORDER_EARNING_ALLOCATION['WonderfulLiving']['Lock']['BrokeragePrice']['Ratio']['code'], CommonEnum::CALCULATE_THE_NUMBER_OF_DECIMAL_PLACES);
41
-
42
-dd($a,$b);
43
-
44
-        // /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
45
-        // $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
46
-        // $sharedProsperityRecommendConfigEntityByMaxRewardRatio = $sharedProsperityRecommendConfigRepository->getSharedProsperityRecommendConfigEntityByMaxRewardRatio();
47
-        // // 利润 减去 顶格的直推奖,剩下的是PV值
48
-        // $pvProportion = bcsub('1', bcdiv($sharedProsperityRecommendConfigEntityByMaxRewardRatio->getRewardRatio(), '100', 4), 2);
49
-        // dd($pvProportion);
50
-
51
-
52
-
53
-        // // 1、获取订单数据
54
-        // /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
55
-        // $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
56
-        // // 获取订单组数据
57
-        // $groupOrderSn = 'wx177442719463317087';
58
-        // $storeGroupOrderEntity = $storeGroupOrderRepository->getStoreGroupOrderEntityByGroupOrderSn($groupOrderSn);
59
-        // /** @var StoreOrderRepository $storeOrderRepository */
60
-        // $storeOrderRepository = app()->make(StoreOrderRepository::class);
61
-        // // 获取订单集合
62
-        // $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
63
-        // try {
64
-        //     Db::transaction(function () use (
65
-        //         $storeGroupOrderRepository,
66
-        //         $storeGroupOrderEntity
67
-        //     ) {
68
-        //         $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
69
-        //     });
70
-        // } catch (\Throwable $e) {
71
-        //     Db::name("log")
72
-        //         ->insert([
73
-        //             'data' => '【订单支付回调】【结算订单失败】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:1111订单失败原因:' . json_encode([
74
-        //                     'error_message' => $e->getMessage(),
75
-        //                     'error_file' => $e->getFile(),
76
-        //                     'error_line' => $e->getLine(),
77
-        //                     'error_code' => $e->getCode(),
78
-        //                     'exception_class' => get_class($e),
79
-        //                     'trace' => $e->getTraceAsString()
80
-        //                 ], JSON_UNESCAPED_UNICODE)
81
-        //         ]);
82
-        //     dd($e->getMessage());
83
-        // }
84
-        //
85
-        //
86
-        // die;
108
+        /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
109
+        $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
110
+        // 共富配置--获取最大的直推奖比例
111
+        $sharedProsperityRecommendConfigEntityByMaxRewardRatio = $sharedProsperityRecommendConfigRepository->getSharedProsperityRecommendConfigEntityByMaxRewardRatio();
112
+        // 共富配置--获取最大的分享奖比例
113
+        $sharedProsperityRecommendConfigEntityByMaxShareRewardRatio = $sharedProsperityRecommendConfigRepository->getSharedProsperityRecommendConfigEntityByMaxShareRatio();
114
+        // 利润 减去 顶格的直推奖,剩下的是PV值
115
+        $sharPveRate = bcadd($sharedProsperityRecommendConfigEntityByMaxRewardRatio->getRewardRatio(),$sharedProsperityRecommendConfigEntityByMaxShareRewardRatio->getShareRatio(), CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
116
+        $pvProportion = bcsub('1', bcdiv($sharPveRate, '100', 4), 2);
87 117
 
88
-        //
89
-        // $title = '系统补贴';
90
-        // $map = [
91
-        //     294 => 165,
92
-        //     186 => 860
93
-        // ];
94
-        //
95
-        // foreach ($map as $uid => $money) {
96
-        //     $bill = [
97
-        //         'uid' => $uid,
98
-        //         'link_id' => 0,
99
-        //         'pm' => 1,
100
-        //         'title' => $title,
101
-        //         'category' => 'now_money',
102
-        //         'type' => 'commission',
103
-        //         'number' => $money,
104
-        //         'balance' => 0,
105
-        //         'mark' => $title,
106
-        //         'create_time' => date('Y-m-d H:i:s'),
107
-        //         'status' => 1,
108
-        //         'commission_type' => CommonEnum::COMMISSION_TYPE['SYSTEM_SUBSIDY_COMMISSION']['code'],
109
-        //         'order_sn' => 0,
110
-        //         'tripartite' => 0,
111
-        //         'type_shop' => 0,
112
-        //         'mer_id' => 0,
113
-        //         'source' => 0,
114
-        //         'order_type' => 1,
115
-        //         'is_red_brokerage' => 0,
116
-        //         'gzc' => 3,
117
-        //         'take_time' => time(),
118
-        //         'district_id' => '',
119
-        //         'street_id' => '',
120
-        //         'month' => '',
121
-        //     ];
122
-        //     $a = Db::name('user_bill')->insert($bill);
123
-        //
124
-        //     $b = Db::name('user')->where('uid', $uid)->inc('brokerage_price', $money)->update();
125
-        // }
126
-        // die;
118
+        dd($pvProportion);
127 119
 
120
+        $orderShareUid = 6;
121
+        $ShareUser = Db::name('shared_prosperity_user')->where(["user_id" => $orderShareUid])->find();
122
+        if ($ShareUser) {
123
+            $rate = Db::name('shared_prosperity_recommend_config')->where(["level" => $ShareUser['partner_level']])->value("share_ratio");
124
+            $rate = $rate / 100;
125
+        }else{
126
+            // 计算 佣金
127
+            $user_group_share_rate = Db::name("system_config_value")->where(["config_key" => "user_group_share_rate"])->value("value");
128
+            $user_group_share_rate = json_decode($user_group_share_rate, true);
129
+            $user_group_share_rate = array_column($user_group_share_rate, 'rate', 'user_groub');
128 130
 
129
-        // $sharedUserPvCount = Db::name('shared_prosperity_reward_record')
130
-        //     ->where(['type' => SharedProsperityRewardRecordEnum::TYPE['PV']['code'], 'status' => SharedProsperityRewardRecordEnum::STATUS['VALID']['code'], 'pm' => SharedProsperityRewardRecordEnum::PM['INCOME']['code']])
131
-        //     ->whereNotIn('user_id',$testUids)
132
-        //     ->sum('number'); // 共富会员专区总业绩
133
-        // dd($sharedUserPvCount);
134
-        // die;
131
+            /** @var UserRepository $userRepository */
132
+            $userRepository = app()->make(UserRepository::class);
133
+            $userEntityByShareUserEntity = $userRepository->getUserEntityByUid($orderShareUid);
134
+            $userGroup = $userEntityByShareUserEntity->getUserGroup();
135
+            $rate = ($user_group_share_rate[$userGroup] ?? 0) / 100;
136
+        }
135 137
 
136
-        //
137
-        $total = 2756.48;
138
-        $map = [
139
-            1 => 0.3,
140
-            2 => 0.15,
141
-            3 => 0.03,
142
-            4 => 0.015,
138
+
139
+        dd($rate);
140
+
141
+
142
+        die;
143
+        $data = [
144
+            'orderId' => '123', // 1688订单号,接口里
145
+            'orderEntryIds' => '123',// 1688子订单号,接口里
146
+            'disputeRequest' => 'refund', // 单选
147
+            'description' => '不想要了', // 填写的
148
+            'applyPayment' => '4.82', // 退款金额,接口里
149
+            'applyCarriage' => '0', // 运费金额,接口里
150
+            'applyReasonId' => '20006', // 退款原因,选的
151
+            'goodsStatus' => 'refundWaitBuyerReceive', // 货物状态,接口里
152
+            'refund_order_id' => 33 // 列表的refund_order_id
143 153
         ];
144
-        $groupMap = [
145
-            1 => 0.1,
146
-            2 => 0.2
154
+
155
+        $orderService = new OrderService();
156
+
157
+        // 构建1688接口参数(前端 disputeRequest 映射为 1688 接口的 disputeReasonId)
158
+        $params = [
159
+            'orderId'         => (string)$data['orderId'],
160
+            'orderEntryIds'   => $data['orderEntryIds'],
161
+            'disputeReasonId' => (string)$data['disputeRequest'],
162
+            'description'     => (string)$data['description'],
163
+            'applyPayment'    => (string)$data['applyPayment'] * 100,
164
+            'applyCarriage'   => (string)$data['applyCarriage'] * 100,
165
+            'applyReasonId'   => (string)$data['applyReasonId'],
166
+            'goodsStatus'     => (string)$data['goodsStatus'],
147 167
         ];
148
-        $testUids = Db::name('user')->where('test_user',  '1')->column('uid');
149
-        $users = Db::name('shared_prosperity_user')->whereNotIn('user_id',$testUids)->group('partner_level')->field('partner_level,count(*) as num')->select()->toArray();
150 168
 
151
-        $res = [];
152
-        foreach ($users as $user) {
153
-            if ($user['partner_level'] == 0 || $user['partner_level'] == 5) {
154
-                continue;
169
+        // 调用1688 API提交售后申请
170
+        $result = $orderService->createRefund($params);
171
+
172
+        // 记录到 store_refund_alibaba 表(不管成功与否都保存原始数据)
173
+        $insertData = [
174
+            'refund_order_id'   => (int)($data['refund_order_id'] ?? 0),
175
+            'alibaba_order_id'  => (string)$data['orderId'],
176
+            'order_entry_ids'   => $data['orderEntryIds'],
177
+            'dispute_reason_id' => (string)$data['disputeRequest'],
178
+            'description'       => (string)$data['description'],
179
+            'goods_status'      => (string)$data['goodsStatus'],
180
+            'apply_payment'     => (string)$data['applyPayment'],
181
+            'apply_carriage'    => (string)$data['applyCarriage'],
182
+            'result_data'       => json_encode($result['rawData'] ?? [], JSON_UNESCAPED_UNICODE),
183
+        ];
184
+
185
+        if ($result['success']) {
186
+            // 提交成功
187
+            $insertData['status'] = 1;
188
+            $insertData['alibaba_refund_id'] = $result['refundId'] ?? '';
189
+            $insertData['alibaba_status'] = $result['status'] ?? '';
190
+            Db::name('store_refund_alibaba')->insert($insertData);
191
+
192
+            // 更新退款单的 after_sn 字段为1688售后单ID
193
+            if (!empty($data['refund_order_id']) && !empty($result['refundId'])) {
194
+                Db::name('store_refund_order')
195
+                    ->where('refund_order_id', (int)$data['refund_order_id'])
196
+                    ->update(['after_sn' => $result['refundId']]);
155 197
             }
156
-            $res[$user['partner_level']] = [
157
-                'num' => $user['num'],
158
-                'money' => $total * $map[$user['partner_level']] / $user['num']
159
-            ];
198
+
199
+            return app('json')->success([
200
+                'alibaba_refund_id' => $result['refundId'] ?? '',
201
+                'alibaba_status'    => $result['status'] ?? '',
202
+            ], '提交1688售后申请成功');
203
+        } else {
204
+            // 提交失败
205
+            $insertData['status'] = 2;
206
+            $insertData['fail_message'] = $result['status'] ?? '1688接口调用失败';
207
+            Db::name('store_refund_alibaba')->insert($insertData);
208
+            return app('json')->fail($result['status'] ?? '提交1688售后申请失败');
209
+        }
210
+
211
+        // $alibabaOrderId = '3300284931845138963';
212
+
213
+        // $orderService = new OrderService();
214
+        // $result = $orderService->getRefundReasonList(['orderId' => $alibabaOrderId]);
215
+
216
+// dd($result);
217
+
218
+        die;
219
+
220
+        // $id = $this->request->params(['pid'])['pid'];
221
+        $id = request()->params(['pid'])['pid'];
222
+        if (!$id) {
223
+            return app('json')->fail('参数不正确');
160 224
         }
161 225
 
162
-        $groupRes = [];
163
-        $groupUsers = Db::name('shared_prosperity_group_user')->whereNotIn('user_id',$testUids)->group('group_id')->field('group_id,count(*)as num')->select()->toArray();
164
-        foreach ($groupUsers as $groupUser) {
165
-            $groupRes[$groupUser['group_id']] = [
166
-                'num' => $groupUser['num'],
167
-                'money' => $total * $groupMap[$groupUser['group_id']] / $groupUser['num']
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+        dd(request());
249
+        $appid = 'wx9082e5ac2fdb513f';
250
+        $sessionKey =str_replace(' ','+', 'AIXeWyu4hRRg0EkD8Z23JA==');
251
+        $encryptedData=str_replace(' ','+','7OCmD5\/4xylVdxYswuTrA6TKzmXNkDymIpdyx9GZIBS+qCIcsBpUnJ5U5GXOTn0JvfQYic9e+0idCTP7QJyJkjjlGWNwwiE0\/WnhBvhAWYlo+Hkh+v3ioiSvqJ7zC4bEJ3GWDNyts5fEX\/u+tL25DySDuUoDoCJs6k+ThlVO5NiecPIcgnmfrLG6nV4Xh3y9H6p\/loj71LRJ47hywX9OQg==');
252
+        $iv =str_replace(' ','+', 'NbjIV0k1DyDWxU7JSSF44w==');
253
+        $pc = new WXBizDataCrypt($appid, $sessionKey);
254
+        $errCode = $pc->decryptData($encryptedData, $iv, $data );
255
+dd($errCode);
256
+        die;
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+        die;
279
+        // ============================================================
280
+        // 通过 ProductService 调用 1688 分销商品列表
281
+        // ============================================================
282
+        try {
283
+            /** @var ProductService $productService */
284
+            $productService = app()->make(ProductService::class);
285
+
286
+            // 设置 access_token(由用户提供或通过OAuth获取)
287
+            $productService->setAccessToken('dc8eab20-f10f-4688-9e45-9ebfa182c7c2');
288
+
289
+            // 搜索参数
290
+            $params = [
291
+                'page'     => 1,      // 页码
292
+                'limit'    => 50,     // 每页条数(最大50)
168 293
             ];
294
+
295
+            $result = $productService->searchProducts($params);
296
+
297
+            if ($result === false) {
298
+                echo "请求失败,请查看日志获取详细信息。\n";
299
+            } else {
300
+                echo "=== 1688分销商品列表 ===\n";
301
+                echo "总数: {$result['total']}\n";
302
+                echo "页码: {$result['page']}\n";
303
+                echo "每页: {$result['pageSize']}\n";
304
+                echo "商品数: " . count($result['list']) . "\n\n";
305
+
306
+                foreach ($result['list'] as $i => $product) {
307
+                    echo ($i + 1) . ". {$product['title']}\n";
308
+                    echo "   商品ID: {$product['productId']}\n";
309
+                    echo "   价格: ¥{$product['minPrice']} ~ ¥{$product['maxPrice']}\n";
310
+                    echo "   月销: {$product['monthSales']}\n";
311
+                    echo "   主图: {$product['mainImage']}\n\n";
312
+                }
313
+            }
314
+
315
+        } catch (\Throwable $e) {
316
+            echo "错误: " . $e->getMessage() . "\n";
317
+            echo "文件: " . $e->getFile() . " (行 " . $e->getLine() . ")\n";
169 318
         }
170
-        dd($res, $groupRes);
319
+
320
+        die;
321
+    }
322
+
323
+    public function posttest()
324
+    {
325
+
326
+
171 327
 
172 328
 
173
-        // 18201226770 4858下的单  改成   13716268932 5064下单
329
+        $sessionKey = request()->post(['sessionKey']);
330
+        $encryptedData = request()->post(['encryptedData']);
331
+        $iv = request()->post(['iv']);
174 332
 
175
-        // 上下级关系正确
333
+        $appid = 'wx9082e5ac2fdb513f';
334
+        $sessionKey =str_replace(' ','+', stripslashes($sessionKey['sessionKey']));
176 335
 
177
-        // 订单所属已修改
336
+        $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
178 337
 
179
-        // 订单产生的共富奖励已修改
338
+        $iv =str_replace(' ','+', stripslashes($iv['iv']));
339
+        
340
+        // $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
341
+        // $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
342
+        // $iv =str_replace(' ','+', $iv['iv']);
180 343
 
181
-        // 佣金修改
344
+        $pc = new WXBizDataCrypt($appid, $sessionKey);
345
+        $errCode = $pc->decryptData($encryptedData, $iv, $data );
346
+        dd($errCode);
347
+    }
348
+
349
+    /**
350
+     * 直接调用示例(不通过ProductService,展示完整流程)
351
+     */
352
+    public function direct()
353
+    {
354
+        $host = 'https://gw.open.1688.com/openapi/';
355
+        $appKey = '6512262';
356
+        $appSecret = 'uNPRZE7895';
357
+        $accessToken = 'dc8eab20-f10f-4688-9e45-9ebfa182c7c2';
358
+        $version = 1;
359
+        $namespace = 'com.alibaba.fenxiao';
360
+        $apiName = 'jxhy.product.getPageList';
361
+
362
+        // 1. 构建URL
363
+        $param = "param2/{$version}/";
364
+        $path = "{$namespace}/{$apiName}/{$appKey}";
365
+        $url = $host . $param . $path;
182 366
 
367
+        // 2. 请求参数
368
+        $data = [
369
+            'access_token' => $accessToken,
370
+            'pageNo' => 1,
371
+            'pageSize' => 10,
372
+        ];
373
+
374
+        // 3. 生成签名
375
+        $aliParams = [];
376
+        foreach ($data as $key => $val) {
377
+            $aliParams[] = $key . $val;
378
+        }
379
+        sort($aliParams);
380
+        $signStr = $param . $path . join('', $aliParams);
381
+        $data['_aop_signature'] = strtoupper(bin2hex(
382
+            hash_hmac("sha1", $signStr, $appSecret, true)
383
+        ));
183 384
 
184
-        // 查询团队业绩
185
-        // $ids = [
186
-        //     1213
187
-        // ];
188
-        // $res = [];
189
-        // foreach ($ids as $id) {
190
-        //     /** @var SharedProsperityUserDao $dao */
191
-        //     $dao = app()->make(SharedProsperityUserDao::class);
192
-        //     $userIds = $dao->getAllSubordinateUserIds($id,true,5);
193
-        //     /** @var SharedProsperityUser $model */
194
-        //     $sum = SharedProsperityUser::getDB()
195
-        //         ->whereIn('user_id', $userIds)
196
-        //         ->sum('pv');
197
-        //     $res[$id] = $sum;
198
-        // }
199
-        // dd($res);
385
+        // 4. 发送POST请求
386
+        $ch = curl_init();
387
+        curl_setopt($ch, CURLOPT_URL, $url);
388
+        curl_setopt($ch, CURLOPT_POST, true);
389
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
390
+        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
391
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
392
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
393
+        $response = curl_exec($ch);
394
+        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
395
+        curl_close($ch);
200 396
 
397
+        $result = json_decode($response, true);
398
+
399
+        echo "HTTP状态码: {$httpCode}\n";
400
+        dump($result);
401
+        die;
402
+    }
403
+
404
+    /**
405
+     * 1688分销商品详情 - 调用示例
406
+     *
407
+     * API: com.alibaba.fenxiao:alibaba.pifatuan.product.detail.list-2
408
+     * 文档: https://open.1688.com/api/apidocdetail.htm?id=com.alibaba.fenxiao%3Aalibaba.pifatuan.product.detail.list-2
409
+     */
410
+    public function detail()
411
+    {
412
+        try {
413
+            /** @var ProductService $productService */
414
+            $productService = app()->make(ProductService::class);
415
+
416
+            // 设置 access_token
417
+            $productService->setAccessToken('dc8eab20-f10f-4688-9e45-9ebfa182c7c2');
418
+
419
+            // 商品ID(从列表接口获取到的 itemId)
420
+            $productId = 642639328505;
421
+
422
+            echo "=== 获取商品详情 ===\n";
423
+            echo "商品ID: {$productId}\n\n";
424
+
425
+            $result = $productService->getProductDetail($productId);
426
+
427
+            echo "=== 原始返回 ===\n";
428
+            var_dump($result);
429
+            echo "\n";
430
+
431
+            if ($result === false) {
432
+                echo "请求失败,请查看日志获取详细信息。\n";
433
+            } else {
434
+                echo "=== 商品详情结果 ===\n";
435
+                echo "标题: " . ($result['title'] ?? 'N/A') . "\n";
436
+                echo "商品ID: " . ($result['productId'] ?? 'N/A') . "\n";
437
+                echo "价格: ¥" . ($result['minPrice'] ?? 0) . " ~ ¥" . ($result['maxPrice'] ?? 0) . "\n";
438
+                echo "库存: " . ($result['stock'] ?? 0) . "\n";
439
+                echo "主图: " . ($result['mainImage'] ?? 'N/A') . "\n";
440
+                echo "SKU数: " . (isset($result['skuList']) ? count($result['skuList']) : 0) . "\n";
441
+                echo "图片数: " . (isset($result['imageList']) ? count($result['imageList']) : 0) . "\n";
442
+            }
443
+
444
+        } catch (\Throwable $e) {
445
+            echo "错误: " . $e->getMessage() . "\n";
446
+            echo "文件: " . $e->getFile() . " (行 " . $e->getLine() . ")\n";
447
+        }
201 448
 
202
-        /** @var SharedProsperityUserRepository $userRepository */
203
-        $userRepository = app()->make(SharedProsperityUserRepository::class);
204
-        $list = $userRepository->getUserTree(294);
205
-        // var_dump(json_encode($list));
206
-        // $field = request()->param('field');
207
-        // /** @var UserRepository $userRepository */
208
-        // $userRepository = app()->make(UserRepository::class);
209
-        // $list = $userRepository->getUserForTree($field, 0);
210
-        var_dump(json_encode($list));
211
-        // return app('json')->success($list);
449
+        die;
212 450
     }
213
-}
451
+}