From bb0973b403e5c9df12568c488a504378b1687c49 Mon Sep 17 00:00:00 2001 From: wang hou sheng <76928547+wanghousheng@users.noreply.github.com> Date: Sun, 12 May 2024 16:19:38 +0800 Subject: [PATCH] 1 --- app/api/controller/StoreKeeper.php | 9 +++++++++ app/common/library/wechat/ShortLink.php | 26 +++++++++++++++++++++++++ app/store/controller/Order.php | 8 ++++++++ 3 files changed, 43 insertions(+) create mode 100644 app/common/library/wechat/ShortLink.php diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index 8159e27d..fbd47bbb 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.php @@ -13,7 +13,9 @@ declare (strict_types=1); namespace app\api\controller; use app\common\enum\RecoveryStatusEnum; +use app\common\library\wechat\ShortLink; use app\common\model\UploadFile; +use app\common\model\wxapp\Setting as WxappSettingModel; use app\store\model\Article as ArticleModel; use app\store\model\article\Category as CategoryModel; use app\store\model\dealer\Order as DealerOrderModel; @@ -193,6 +195,11 @@ class StoreKeeper extends Controller return $this->renderSuccess(compact('list')); } else { $model = new OrderModel; + $store_id = OrderModel::$storeId; + // 小程序配置信息 + $wxConfig = WxappSettingModel::getConfigBasic($store_id); + // 请求api获取短连接 + $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); $list = $model->getNewList($params); if (!empty($list['data'])) { foreach ($list['data'] as $key => $value) { @@ -220,6 +227,7 @@ class StoreKeeper extends Controller $copy_text .= "单价:{$good['goods_price']}\n"; $copy_text .= "数量:{$good['total_num']}\n"; $copy_text .= "总价:{$good['total_price']}\n"; + $copy_text .= "商品链接:" . $link_obj->shortUrl("/pages/goods/detail?goodsId=" . $good['goods_id'], '商品详情'); $copy_text .= "\n"; } if (!empty($value['address'])) { @@ -232,6 +240,7 @@ class StoreKeeper extends Controller } $copy_text .= "地址:$address{$value['address']['detail']}\n"; } + $list['data'][$key]['copy_text'] = $copy_text; } } diff --git a/app/common/library/wechat/ShortLink.php b/app/common/library/wechat/ShortLink.php new file mode 100644 index 00000000..e8f1e9c3 --- /dev/null +++ b/app/common/library/wechat/ShortLink.php @@ -0,0 +1,26 @@ +getAccessToken(); + $url = "https://api.weixin.qq.com/wxa/genwxashortlink?access_token=$accessToken"; + $data = [ + 'page_url' => $page_url, + 'page_title' => $page_title, + 'is_permanent' => $is_permanent, + ]; + $result = $this->post($url, helper::jsonEncode($data)); + $response = $this->jsonDecode($result); + if (!empty($response['link'])) { + return $response['link']; + } + return $response['errmsg'] ?? ''; + } +} \ No newline at end of file diff --git a/app/store/controller/Order.php b/app/store/controller/Order.php index 999b7e18..9d384b61 100644 --- a/app/store/controller/Order.php +++ b/app/store/controller/Order.php @@ -12,6 +12,8 @@ declare (strict_types=1); namespace app\store\controller; +use app\common\library\wechat\ShortLink; +use app\common\model\wxapp\Setting as WxappSettingModel; use app\store\model\Order as OrderModel; use think\response\Json; @@ -33,6 +35,11 @@ class Order extends Controller $model = new OrderModel; $result = $model->getList($this->request->param()); $data = $result->items(); + $store_id = OrderModel::$storeId; + // 小程序配置信息 + $wxConfig = WxappSettingModel::getConfigBasic($store_id); + // 请求api获取短连接 + $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); if (!empty($data)) { foreach ($data as $key => $value) { $data[$key]['address_match_text'] = '--'; @@ -45,6 +52,7 @@ class Order extends Controller $copy_text .= "单价:{$good['goods_price']}\n"; $copy_text .= "数量:{$good['total_num']}\n"; $copy_text .= "总价:{$good['total_price']}\n"; + $copy_text .= "商品链接:" . $link_obj->shortUrl("/pages/goods/detail?goodsId=" . $good['goods_id'], '商品详情'); $copy_text .= "\n"; } if (!empty($value['address'])) {