ソースを参照

feat: 微信公众号h5授权-v3

John-Hong 2 年 前
コミット
1a4bf9dbd9
4 ファイル変更17 行追加7 行削除
  1. 4 0
      nginx_parking.conf
  2. 8 3
      src/pages/login/openWx.vue
  3. 1 1
      src/utils/login.js
  4. 4 3
      src/utils/request-kip.js

+ 4 - 0
nginx_parking.conf

@@ -15,6 +15,10 @@ server {
         proxy_pass https://qa-apim.kerryplus.com/c/api/payment/v1;
     }
 
+    location /weixin {
+        proxy_pass https://api.weixin.qq.com;
+    }
+
 
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {

+ 8 - 3
src/pages/login/openWx.vue

@@ -13,7 +13,7 @@ export default {
     console.log(12121212);
     this.getCode();
   },
-  mounted(){
+  mounted() {
     console.log(17171717171717);
   },
   methods: {
@@ -29,7 +29,7 @@ export default {
           `wx907c27f16841a919` +
           '&redirect_uri=' +
           encodeURIComponent(local) +
-          '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect';
+          '&response_type=code&scope=snsapi_base&state=1#wechat_redirect';
       } else {
         this.getOpenId(code); //把code传给后台获取用户信息
       }
@@ -37,10 +37,15 @@ export default {
     async getOpenId(code) {
       // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
       let _this = this;
+
+      // ?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
       const res = await WxJsOpenId({
+        appid: 'wx907c27f16841a919',
+        secret: 'd9c81d6c47f7de322a2ff85847de6728',
         code,
+        grant_type: 'authorization_code',
       });
-      console.log(res);
+      console.log(4848484848, res);
       //   this.$http
       //     .post('/api/user/wechat/login', { code: code })
       //     .then((res) => {

+ 1 - 1
src/utils/login.js

@@ -104,7 +104,7 @@ export function logout() {
  }>
  */
 export function WxJsOpenId( param ) {
-  return request.post(`/oauth/v1/wx/config/openId`,param);
+  return request.get(`/weixinApi/sns/oauth2/access_token`,param);
 }
 
 // H5获取微信签名信息Api - 需要登录

+ 4 - 3
src/utils/request-kip.js

@@ -56,17 +56,18 @@ function getUrl( path ) {
   // 如果是dev、qa、prod环境
   if (window.ininjectConfig) {
     if(path.indexOf('/profileApi') > -1) {
-      console.log(58, path);
       return `${window.ininjectConfig.profileApi}${path}`
     }
+    if (/weixinApi/g.test(path)) {
+      return path;
+    }
     if(/\/qaPayment/g.test(path)) {
-      console.log(58, path);
       return `${window.ininjectConfig.qaPayment}${path}`
     }
   }
   // 本地开发环境
   // path.indexOf('http') > -1 && 
-  if (path.indexOf('/profileApi') > -1 ) {
+  if (path.indexOf('/profileApi') > -1 || path) {
     return path;
   } else if (/\/qaPayment/g.test(path)) {
     // 支付