qiushang 1 vuosi sitten
vanhempi
commit
ee9e4280d8
1 muutettua tiedostoa jossa 10 lisäystä ja 18 poistoa
  1. 10 18
      app/Http/Api/WechatOfficialController.php

+ 10 - 18
app/Http/Api/WechatOfficialController.php

@@ -47,20 +47,6 @@ class WechatOfficialController extends HttpBaseController
         }
     }
 
-    public function index3()
-    {
-        $this->app->template_message->send([
-            'touser' => 'oML8X6YkbviDESdya_RCfgdmUtSQ',
-            'template_id' => 'demGYbEZInVgvwO1ClJNuz2Hc-0FYWZp_duv7HSgdmw',
-            'url' => 'https://easywechat.com',
-            'data' => [
-                'thing2' => '黄先生(1002)',
-                'thing3' => '湖南友投CMIDERP',
-                'time6' => '2024-02-21 9:58:23'
-            ]
-        ]);
-    }
-
     public function index2()
     {
         $this->app->server->push(function ($message) {
@@ -195,11 +181,16 @@ class WechatOfficialController extends HttpBaseController
         }
 
         if ($isSuccess) {
+            $oauthUrl = 'https://www.xingyousoft.com';
+            if ($sceneStr) {
+                $oauthUrl = $this->app->oauth->withState(base64_encode($sceneStr))->redirect();
+            }
+
             // 发送登录成功消息
             $this->app->template_message->send([
                 'touser' => $openid,
                 'template_id' => 'demGYbEZInVgvwO1ClJNuz2Hc-0FYWZp_duv7HSgdmw',
-                'url' => 'https://www.xingyousoft.com',
+                'url' => $oauthUrl,
                 'data' => [
                     'thing2' => $nickname,
                     'thing3' => $productTitle,
@@ -228,7 +219,7 @@ class WechatOfficialController extends HttpBaseController
             case 'subscribe':  // 1. 用户未关注时,进行关注后的事件推送
             case 'SCAN': // 2. 用户已关注时的事件推送
                 if (empty($sceneStr)) {
-                    return "欢迎你关注助友办公软件";
+                    return "欢迎你关注办公软件";
                 } else {
                     $oauthUrl = $this->app->oauth->withState(base64_encode($sceneStr))->redirect();
                     //$oauthUrl = str_replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1edb103f32029099&redirect_uri=https%3A%2F%2Fwww.xingyousoft.com%2Fapi%2Fwechat%2FoauthCallback&response_type=code&scope=snsapi_userinfo&state=WHdCeXhSMW5vUHgzOjUyNDEzYTY3MWVjNzAzNDc4M2FhMWEzMDMyNmRlMjNk&connect_redirect=1#wechat_redirect', '', $oauthUrl);
@@ -387,13 +378,14 @@ class WechatOfficialController extends HttpBaseController
         } else {
             // 插入数据
             $isSuccess = DB::transaction(function () use ($openid, $nickname, $avatar, $unionid, $wxInfo) {
+                $mid = Str::random(12);
                 $userData = [
                     'username' => $nickname,
                     'avatar' => $avatar,
                     'roles' => json_encode([1]),
                     'unionid' => $unionid,
                     'status' => 1,
-                    'mid' => Str::random(12),
+                    'mid' => $mid,
                     'created_at' => time(),
                     'updated_at' => time(),
                 ];
@@ -406,7 +398,7 @@ class WechatOfficialController extends HttpBaseController
                     'nick' => $nickname,
                     'wx_avatar' => $avatar,
                     'wx_info' => json_encode($wxInfo),
-                    'mid' => Str::random(12),
+                    'mid' => $mid,
                     'created_at' => time(),
                     'updated_at' => time(),
                 ];