From 9b5ef9deedc30d6f596114ab981da802d140090b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Fri, 7 Jul 2023 15:27:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#10000=20=E5=BF=AB=E5=9B=A2=E5=9B=A2?= =?UTF-8?q?=E7=94=B5=E5=AD=90=E9=9D=A2=E5=8D=95=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Test.php | 11 ++++ app/Http/Controllers/Shop/ShopsController.php | 7 +++ app/Services/PrintModule/Pdd/Ktt.php | 63 +++++++++++++++++++ routes/web.php | 2 + 4 files changed, 83 insertions(+) create mode 100644 app/Services/PrintModule/Pdd/Ktt.php diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 658154a..44ccfaa 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -53,5 +53,16 @@ class Test extends Command */ public function handle() { + $shops = Shop::query()->where('plat_id', Shop::$PLAT_KTT)->where('status', Shop::$STATUS_AUTHORIZED)->where('id', 6)->get(); + foreach ($shops as $shop) { + $faceSheet = new FaceSheet(); + $faceSheet->setShop($shop); + var_dump($faceSheet->searchWayBill()); + } + } + + public function getAuthUrl() + { + return "https://wb.pinduoduo.com/logistics/auth?client_id=24f25877aca447c5830a6aa896301d5e&redirect_uri=http://erp.chutang66.com/pdd/ship"; } } diff --git a/app/Http/Controllers/Shop/ShopsController.php b/app/Http/Controllers/Shop/ShopsController.php index 26af3b6..35b24b2 100644 --- a/app/Http/Controllers/Shop/ShopsController.php +++ b/app/Http/Controllers/Shop/ShopsController.php @@ -7,6 +7,7 @@ use App\Models\BusinessGoodsSku; use App\Models\GoodsSku; use App\Models\Shop; use App\Http\Resources\ShopsResource; +use App\Services\PrintModule\Pdd\Ktt; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; @@ -218,4 +219,10 @@ class ShopsController extends Controller return response($this->res, $this->res['httpCode']); } + + public function pddPrintAuth(Request $request) + { + $ktt = new Ktt(); + $ktt->auth($request->get('code')); + } } diff --git a/app/Services/PrintModule/Pdd/Ktt.php b/app/Services/PrintModule/Pdd/Ktt.php new file mode 100644 index 0000000..34c5752 --- /dev/null +++ b/app/Services/PrintModule/Pdd/Ktt.php @@ -0,0 +1,63 @@ +getAccessTokenWithCode($code); + LogFile::info('电子面单应用授权: ' . json_encode($accessToken, 256)); + } + + protected function getAccessTokenWithCode($code) + { + $type = 'pdd.pop.auth.token.create'; + $res = $this->doRequest($type, ['code' => $code]); + + return $res['pop_auth_token_create_response']; + } + + public function doRequest($type, $appendParams = [], $url = 'https://gw-api.pinduoduo.com/api/router') + { + $publicParams = [ + 'type' => $type, + 'client_id' => $this->clientId, + 'timestamp' => time() + ]; + $publicParams = array_merge($publicParams, $appendParams); + $publicParams['sign'] = $this->getSign($publicParams); + + return $this->formDataPostRequest($url, $publicParams); + } + + protected function getSign($params) + { + ksort($params); + $str = ''; + foreach ($params as $key => $val) { + $str .= $key . $val; + } + $str = $this->clientSecret . $str . $this->clientSecret; + + return strtoupper(md5($str)); + } + + protected function formDataPostRequest($url, $params) + { + $method = 'POST'; + $headers = [ + 'headers' => ['Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'], + 'form_params' => $params + ]; + $res = (new Client())->request($method, $url, $headers); + return json_decode($res->getBody()->getContents(), true); + } +} diff --git a/routes/web.php b/routes/web.php index 27743c3..fc27246 100644 --- a/routes/web.php +++ b/routes/web.php @@ -28,3 +28,5 @@ Route::get('today_price/export', [BusinessGoodsSkusController::class, 'exportTod Route::get('goods/import/template', [GoodsController::class, 'download'])->name('download.goods_import.template'); Route::get('callback', [ShopsController::class, 'authBind'])->name('shop.auth_bind.callback'); + +Route::get('pdd/ship', [ShopsController::class, 'pddPrintAuth'])->name('shop.pdd_print.callback');