|
@@ -0,0 +1,166 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace app\controller\v2;
|
|
|
|
|
+
|
|
|
|
|
+use app\extra\basic\Base;
|
|
|
|
|
+use app\extra\dyLife\Crypt;
|
|
|
|
|
+use app\middleware\AuthMiddleware;
|
|
|
|
|
+use app\model\saas\SaasGoods;
|
|
|
|
|
+use app\model\saas\SaasStore;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\Controller;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\GetMapping;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\Middleware;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\PostMapping;
|
|
|
|
|
+use support\Request;
|
|
|
|
|
+use support\Response;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#[Controller("/v2/home"),Middleware(AuthMiddleware::class)]
|
|
|
|
|
+class Home extends Base
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @var array|string[]
|
|
|
|
|
+ */
|
|
|
|
|
+ protected array $noNeedLogin = ["getHomeData","getLicense","payBtnMobile","getMoreGoods","getCityJson"];
|
|
|
|
|
+
|
|
|
|
|
+ #[GetMapping("data")]
|
|
|
|
|
+ public function getHomeData(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "store.require" => trans("empty.require")
|
|
|
|
|
+ ],$request->method());
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $store = (new SaasStore)->where("poi_id",$param['store'])->field("poi_name,start_at,end_at,longitude,latitude,service_mobile,poi_id,poi_city,poi_address,poi_logo")->findOrEmpty();
|
|
|
|
|
+ if (!$store->isEmpty()) {
|
|
|
|
|
+ $store['poi_logo'] = empty($store['poi_logo']) ? sConf("service.logo") : $store['poi_logo'];
|
|
|
|
|
+ }
|
|
|
|
|
+ $goods = (new SaasGoods)->where("poi_id",$param['store'])->where("status",1)->field("product_id,product_name,image_list,category,price,line_price,sale_stock,id")->limit(10)->order('id','desc')->select()->toArray();
|
|
|
|
|
+ return success("ok",compact('store','goods'));
|
|
|
|
|
+ } catch (\Throwable $th) {
|
|
|
|
|
+ return error($th->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[GetMapping("goods")]
|
|
|
|
|
+ public function getMoreGoods(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "store.require" => trans("empty.require"),
|
|
|
|
|
+ "page.default" => 1,
|
|
|
|
|
+ "size.default" => 10
|
|
|
|
|
+ ],$request->method());
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $goods = (new SaasGoods)->where("poi_id",$param['store'])->where("status",1)->field("product_id,product_name,image_list,category,price,line_price,sale_stock,id,goods_id")->limit(10)->order('id','desc')->paginate([
|
|
|
|
|
+ "list_rows" => $param['size'],
|
|
|
|
|
+ "page" => $param['page']
|
|
|
|
|
+ ]);
|
|
|
|
|
+ return successTrans(100010,pageFormat($goods),200);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ #[GetMapping("license")]
|
|
|
|
|
+ public function getLicense(): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return success("ok",['img' => sConf("service.license")]);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 三级城市信息
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[GetMapping("city")]
|
|
|
|
|
+ public function getCityJson(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $data = json_decode(file_get_contents(base_path()."/city.json"),true);
|
|
|
|
|
+ return successTrans("success.data",$data);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 生服组件解密手机号码
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[PostMapping("mobile")]
|
|
|
|
|
+ public function payBtnMobile(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->all();
|
|
|
|
|
+ $mobile = [];
|
|
|
|
|
+ if (!empty($param['code'])) {
|
|
|
|
|
+ $sessionKey = (new Crypt)->config($this->getDyConfig())->token()->getSessionKey($param['code']);
|
|
|
|
|
+ if (!empty($sessionKey)) {
|
|
|
|
|
+ $mobileStr = $this->decrypt2code($param['encryptedData'], $sessionKey['session_key'],$param['iv']);
|
|
|
|
|
+ if (!empty($mobileStr)) $mobile = json_decode($mobileStr,true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($mobile)) return error("获取失败");
|
|
|
|
|
+ return successTrans("success.data",['mobile' => $mobile['purePhoneNumber']]);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解密微信用户手机号等加密数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $encrypted_data Base64 编码的密文
|
|
|
|
|
+ * @param string $session_key Base64 编码的会话密钥
|
|
|
|
|
+ * @param string $iv Base64 编码的初始向量
|
|
|
|
|
+ * @return string 解密后的原始字符串(通常为 JSON)
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
|
|
+ protected function decrypt2code($encrypted_data, $session_key, $iv)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 1. Base64 解码
|
|
|
|
|
+ $data = base64_decode($encrypted_data, true);
|
|
|
|
|
+ $key = base64_decode($session_key, true);
|
|
|
|
|
+ $iv = base64_decode($iv, true);
|
|
|
|
|
+
|
|
|
|
|
+ if ($data === false || $key === false || $iv === false) {
|
|
|
|
|
+ throw new \Exception('Base64 解码失败');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 根据密钥长度选择 AES 算法
|
|
|
|
|
+ $key_len = strlen($key);
|
|
|
|
|
+ switch ($key_len) {
|
|
|
|
|
+ case 16:
|
|
|
|
|
+ $method = 'AES-128-CBC';
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 24:
|
|
|
|
|
+ $method = 'AES-192-CBC';
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 32:
|
|
|
|
|
+ $method = 'AES-256-CBC';
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ throw new \Exception("无效的密钥长度: {$key_len} 字节");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 解密(OPENSSL_RAW_DATA 表示返回二进制数据,不进行 Base64 编码)
|
|
|
|
|
+ $decrypted = openssl_decrypt($data, $method, $key, OPENSSL_RAW_DATA, $iv);
|
|
|
|
|
+
|
|
|
|
|
+ if ($decrypted === false) {
|
|
|
|
|
+ throw new \Exception('解密失败: ' . openssl_error_string());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $decrypted;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|