uniapp official account for local authorization and debugging

1. Modify the local hosts file

  • Find the hosts file under C:\Windows\System32\drivers\etc and open the file like this
    Insert image description here
  • Comment the last line and start a new line, change it to
127.0.0.1 你需要修改的地址,例如:www.baidu.com
  • Remember to save after modification. If it cannot be saved, you must save it as an administrator.

2. Refresh DNS cache

  • cmd executionipconfig /flushdns, this can refresh the DNS cache and make the hosts file just modified take effect in time.Insert image description here

3. Configure project agent

  • Open the official account project of uniapp, open the source code view of the manifest.json file, and add the following configuration items into it
	"h5": {
    
    
		"devServer": {
    
    
			"host": "www.baidu.com", // 用于指定devDerve使用的host,就是公众号项目存放的服务器地址,与hosts文件配置的一致
			"port": 80, // 指定要监听请求的端口号,公众号项目的端口地址,默认80端口
			"proxy": {
    
    
				"/api": {
    
    
					"target": "http://192.168.50.23:8188", // 请求的后端服务器地址
					"ws": false, // 是否代理websockets
					"changeOrigin": true, // 默认值:false 将主机标头的原点更改为目标URL
					"secure": false, // 是否验证SSL Certs
					"pathRewrite": {
    
     
						"^/api": "/api" // 重写之后url为 http://192.168.50.23:8188/api/xxx
					}
				}
			}
		},
		// 其他配置项
	},
  • Then restart the project and you will find that the startup address of the project becomeshttp://www.baidu.com:80/, and also pay attention to whether the local project port is occupied
  • Enter in WeChat developer toolshttp://www.qtpiano.com, note that it is an http request, not https

4. Configuration completed

  • Now debugging authorization login in WeChat developer tools can be authorized normally, but debugging WeChat payment will still be abnormal.
{
    
    errMsg: "chooseWXPay:没有此SDK或暂不支持此SDK模拟"}
  • There is also a/sockjs-node/infoI don’t know how to solve the interface refresh problem.
  • If you have any insights, please explain it in the comment area.

Guess you like

Origin blog.csdn.net/morensheng/article/details/132473762