Forráskód Böngészése

chore: 增加 getuserdetail 调用前参数弹窗

首页新增请求参数弹窗,先展示 getuserdetail 请求的 access_token 和 user_ticket,再展示接口返回。同步在内部成员分支回传调用前参数,便于排查 token 与 ticket 传参问题。

Made-with: Cursor
haifeng.zhang 1 hete
szülő
commit
0e488b4a23
2 módosított fájl, 28 hozzáadás és 8 törlés
  1. 12 1
      src/api/wecom/index.ts
  2. 16 7
      src/pages/home/index.vue

+ 12 - 1
src/api/wecom/index.ts

@@ -180,6 +180,9 @@ export function getWecomUserDetail(userTicket: string) {
     (accessToken) => ({
       url: '/cgi-bin/auth/getuserdetail',
       method: 'POST',
+      params: {
+        access_token: accessToken,
+      },
       data: {
         access_token: accessToken,
         user_ticket: userTicket,
@@ -334,6 +337,7 @@ export async function syncExternalVisitorProfile(code: string) {
       internalUserRaw: undefined,
       userTicket: undefined,
       debugAccessToken: undefined,
+      getuserdetailRequestParams: undefined,
     }
   }
 
@@ -343,12 +347,17 @@ export async function syncExternalVisitorProfile(code: string) {
     let detailRaw: WecomUserDetailResponse | undefined
     let detailMobile = ''
     let debugAccessToken = ''
+    let getuserdetailRequestParams: Record<string, string> | undefined
     if (userInfo.user_ticket) {
+      debugAccessToken = getCachedAccessToken()
+      getuserdetailRequestParams = {
+        access_token: debugAccessToken,
+        user_ticket: userInfo.user_ticket,
+      }
       try {
         const detail = await getWecomUserDetail(userInfo.user_ticket)
         detailRaw = detail
         detailMobile = (detail.mobile || '').trim()
-        debugAccessToken = getCachedAccessToken()
       } catch {
         detailMobile = ''
       }
@@ -368,6 +377,7 @@ export async function syncExternalVisitorProfile(code: string) {
       internalUserRaw: detailRaw,
       userTicket: userInfo.user_ticket || '',
       debugAccessToken,
+      getuserdetailRequestParams,
     }
   }
 
@@ -379,5 +389,6 @@ export async function syncExternalVisitorProfile(code: string) {
     internalUserRaw: undefined,
     userTicket: undefined,
     debugAccessToken: undefined,
+    getuserdetailRequestParams: undefined,
   }
 }

+ 16 - 7
src/pages/home/index.vue

@@ -34,6 +34,8 @@ const stripOAuthCodeFromUrl = () => {
 const externalUserid = ref('');
 const unionidValue = ref('');
 const ownerId = ref('');
+const getuserdetailRequestPopupVisible = ref(false);
+const getuserdetailRequestJsonText = ref('');
 const internalUserGetPopupVisible = ref(false);
 const internalUserGetJsonText = ref('');
 
@@ -86,14 +88,14 @@ const bootstrapWithCode = async (code: string) => {
     throw new Error('identity incomplete')
   }
   applyVisitorFromSyncResult(result)
-  if (result.internalUserRaw) {
-    internalUserGetJsonText.value = JSON.stringify({
-      authParams: {
-        user_ticket: result.userTicket || '',
-        access_token: result.debugAccessToken || '',
-      },
-      getuserdetail: result.internalUserRaw,
+  if (result.getuserdetailRequestParams) {
+    getuserdetailRequestJsonText.value = JSON.stringify({
+      authParams: result.getuserdetailRequestParams,
     }, null, 2)
+    getuserdetailRequestPopupVisible.value = true
+  }
+  if (result.internalUserRaw) {
+    internalUserGetJsonText.value = JSON.stringify(result.internalUserRaw, null, 2)
     internalUserGetPopupVisible.value = true
   }
 }
@@ -164,6 +166,13 @@ const getQuestionPage = () => {
     </view>
     <img class="box_bg_bottom" src="@/assets/bg_bottom.png" alt="" srcset="">
 
+    <van-popup v-model:show="getuserdetailRequestPopupVisible" round closeable class="user-get-popup">
+      <view class="user-get-popup__header">getuserdetail 请求参数</view>
+      <scroll-view scroll-y class="user-get-popup__content">
+        <text selectable class="user-get-popup__json">{{ getuserdetailRequestJsonText }}</text>
+      </scroll-view>
+    </van-popup>
+
     <van-popup v-model:show="internalUserGetPopupVisible" round closeable class="user-get-popup">
       <view class="user-get-popup__header">getuserdetail 返回</view>
       <scroll-view scroll-y class="user-get-popup__content">