简单来说内网穿透的目的是:让外网能访问你本地的应用,例如在外网打开你本地http://127.0.0.1指向的Web站点。
在这里有一篇播客,详细介绍了几种内网穿透策略:一分钟了解内网穿透
这里我们使用一个免费的内网穿透工具:Natapp:NATAPP官网
详细教程在这里:一分钟的natapp快速新手教程
百度网盘
链接:https://pan.baidu.com/s/1oRcs6nF3WS_h7nsaB6dfPg
提取码:zycx
#1.购买隧道
#2.在我的隧道中记录token:
#3.下载软件:
注意,这里下载的只有软件,没有配置文件,启动的时候,需要手动指定authtoken,资料里面我给大家提供好了一个带有配置文件的软件:
解压:
启动后的样子:
比如此处,我使用的natapp得到的域名是:http://9xtfjr.natappfree.cc,并且我设置指向到127.0.0.1:10010
位置,也就是我的网关服务。
下面的4.5.6是对微信支付的回调地址(未备案的)做的
#4.配置回调地址
设置内网穿透地址到配置文件application.yml:
ly:
pay:
wx:
appID: wx8397f8696b538317
mchID: 1473426802
key: T6m9iK73b0kn9g5v426MKfHQH7X8rKwb
notifyUrl: http://xn4agt.natappfree.cc/api/pay/wx/notify
payType: NATIVE
WxPayConfigImpl中本来就有notifyURL属性,因此会被自动注入。
#5.网关白名单
因为异步回调是微信来访问我们的,因此不应该对登录做校验,我们把这个地址配置到白名单,修改ly-gateway中的application.yml
6.拦截器对微信的回调地址放开配置
package com.leyou.order.config;
import com.leyou.order.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Autowired
private UserInterceptor userInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(userInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/pay/wx/notify");
}
}