diff --git a/app/Http/Controllers/WeChatController.php b/app/Http/Controllers/WeChatController.php index b5a4f4b..3fd043d 100644 --- a/app/Http/Controllers/WeChatController.php +++ b/app/Http/Controllers/WeChatController.php @@ -8,10 +8,12 @@ use Yo; class WeChatController extends Controller { - public function auth(Request $request) + public function auth($app_id) { - $code = $request->get('code'); - $state = $request->get('state'); + $code = request()->get('code'); + $state = request()->get('state'); + $we_chat = WeChat::where('app_id', $app_id)->where('type', 1)->first(); + if (!$we_chat) return Yo::error_echo(100001, ['公众号']); $url = $state . "code=$code"; Yo::echo(['url' => $url]); header("Location: $url"); diff --git a/routes/web.php b/routes/web.php index eca4a46..d60aceb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Route; $admin_path = 'Admin'; $zero_path = 'Zero'; $app_path = 'App'; -Route::get("open/Gzh/auth", [\App\Http\Controllers\WeChatController::class, 'auth']); +Route::get("open/Gzh/auth/{app_id}", [\App\Http\Controllers\WeChatController::class, 'auth']); Route::get("api/Test/Excel/excel_test", [\App\Http\Controllers\ExcelController::class, 'excel_test']); Route::post("api/Test/Email/email_test", [\App\Http\Controllers\EmailController::class, 'email_test']); diff --git a/uniapp/api/index.js b/uniapp/api/index.js index a2ef314..d833f7f 100644 --- a/uniapp/api/index.js +++ b/uniapp/api/index.js @@ -4,12 +4,19 @@ import { import $config from '@/config.js' const app_path = 'App' let url = '' +let gzh = { + id: '', + jump: '', + auth: '' +} const urlPick = () => { if ($config.config.length > 0) { url = $config.config[0].url + gzh = $config.config[0].gzh for (let i in $config.config) { if (!!$config.config[i].active) { url = $config.config[i].url + gzh = $config.config[i].gzh break } } @@ -17,7 +24,7 @@ const urlPick = () => { } urlPick() -export const OpenGzhAuthUrl = `${url}/open/Gzh/auth` +export const GzhConfig = gzh export const WeChatPayPayTestAction = async (data) => await $post({ url: `${url}/api/Test/WeChatPay/pay_test`, data diff --git a/uniapp/config.js b/uniapp/config.js index 3b00d3c..aa07c50 100644 --- a/uniapp/config.js +++ b/uniapp/config.js @@ -3,14 +3,16 @@ const config = [{ url: 'http://lucode3.sa0.online', gzh: { id: 'wx526430047d34c85c', - jump: 'http://node/h5/#/pages/package/gzh_auth/gzh_auth?' + jump: 'https://lucode3.sa0.online/h5/#/pages/gzh/login/login?', + auth: 'https://lucode3.sa0.online/open/Gzh/auth/wx526430047d34c85c' }, }, { active: false, url: 'http://127.0.0.1:8000', gzh: { id: 'wx526430047d34c85c', - jump: 'http://127.0.0.1:5173/h5/#/pages/gzh/login/login?' + jump: 'http://127.0.0.1:5173/h5/#/pages/gzh/login/login?', + auth: 'https://lucode3.sa0.online/open/Gzh/auth/wx526430047d34c85c' }, }] uni.$config = JSON.parse(JSON.stringify(config)) diff --git a/uniapp/pages.json b/uniapp/pages.json index 8296ae5..318207b 100644 --- a/uniapp/pages.json +++ b/uniapp/pages.json @@ -2,7 +2,8 @@ "pages": [{ "path": "pages/main/index/index", "style": { - "navigationBarTitleText": "鹿和开发模板" + "navigationBarTitleText": "鹿和开发模板", + "navigationStyle": "custom" } }, { "path": "pages/main/my/my", diff --git a/uniapp/pages/dev/example/UserGzh/UserGzh.vue b/uniapp/pages/dev/example/UserGzh/UserGzh.vue index 04ca8c5..8690149 100644 --- a/uniapp/pages/dev/example/UserGzh/UserGzh.vue +++ b/uniapp/pages/dev/example/UserGzh/UserGzh.vue @@ -8,24 +8,16 @@ ref } from 'vue' import { - OpenGzhAuthUrl, - WeChatLoginTestAction, + GzhConfig, $response } from '@/api' - const user_code = ref('') const wxGetUserInfo = (res) => { - if (!res.detail.iv) { - uni.$lu.toast("您取消了授权,登录失败"); - return false; - } - uni.login({ - provider: 'weixin', - success: (loginRes) => { - let d = loginRes - user_code.value = JSON.stringify(d, null, 4) - drawer_ref.value.open() - }, - }); + let appid = GzhConfig.id + let state = encodeURIComponent(GzhConfig.auth) + let redirect_uri = encodeURIComponent(GzhConfig.jump); + const url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=' + + redirect_uri + '&response_type=code&scope=snsapi_base&state=' + state + '#wechat_redirect'; + window.location = url; } const drawer_ref = ref(null) @@ -59,7 +51,7 @@ - + diff --git a/uniapp/pages/dev/proxy/proxy.vue b/uniapp/pages/dev/proxy/proxy.vue index 6a7c621..542b207 100644 --- a/uniapp/pages/dev/proxy/proxy.vue +++ b/uniapp/pages/dev/proxy/proxy.vue @@ -124,11 +124,17 @@ - 授权地址 + 跳转地址 + + 授权地址 + + + + 激活状态 @@ -160,11 +166,17 @@ - 授权地址 + 跳转地址 + + 授权地址 + + + + 激活状态