vue3.0 配置请求跨域nginx代理转发 微信 {"errcode":40066,"errmsg":"invalid url hint: [FZbxRA0556sz12!]"}错误

1.vue-cli3.0项目 新建一个vue.config.vue文件中配置代理路径

devServer: {
        // port: 3000, // 端口号
        // 允许外网访问
        //disableHostCheck: true,
        proxy: {
            '/wxapi': {     //这里最好有一个 /
                target: 'https://api.weixin.qq.com/',  // 后台接口域名
                //ws: true,
                changeOrigin: true,  //是否跨域
                pathRewrite:{
                    '^/wxapi':''
                }
            },
        }
    },

2.访问路径跟改为

getAccessTokenUrl: '/wxapi/sns/oauth2/access_token', //获取openid

#axios请求接口 params请求微信接口参数
getAccessToken({dispatch, commit, state}, params) {
       return http({
                method: 'GET',
                url: state.getAccessTokenUrl + '?' + qs.stringify(params)
       })
},

3.nginx配置代理转发

location /wxapi { #添加访问目录为/apis的代理配置
      rewrite  ^/wxapi/(.*)$ /$1 break;  #重定向(这个必须配置否则微信40066错误)
      proxy_pass  https://api.wein.qq.com;  #目标地址
}

4.重启nginx服务,完美解决

发布了16 篇原创文章 · 获赞 6 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/LGDmar/article/details/105508690