当前位置:网站首页>小程序referer
小程序referer
2022-06-27 20:47:00 【云闲不收】
小程序如何根据referer跳转不同的后台环境
这篇文章主要讲解了“小程序如何根据referer跳转不同的后台环境”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“小程序如何根据referer跳转不同的后台环境”吧!
一、问题:
开发小程序的时候有4个版本(开发、体验、审核、正式)。所以不同的环境要请求不同的后台。特别是审核版本,因为还要微信审核,如果请求错误,会被审核失败。因为生产环境是对应旧的后台版本,所以审核版本既不能调到后台生产环境,也不能跳到开发环境。
我们为了方便生产、审核2个版本小程序都去请求/prod。这里就要区别真实的请求到底是从生产、审核哪里来的。
二、解决思路。
微信给我们服务器发送请求wx.request的会带上一个referer的header参数。格式如下:
https://servicewechat.com///page-frame.html
其中<appId>是发送请求的小程序appId,<version>是小程序的版本。
开发、体验、审核 版本中version值是0,开发工具中version值是devtools。
正式版的version值是大于0的正整数,表示这个小程序发布到正式版多少次。 例子如下:
开发版:
https://servicewechat.com/小程序appId/0/page-frame.html
体验版:
https://servicewechat.com/小程序appId/0/page-frame.html
devtools:
https://servicewechat.com/小程序appId/devtools/page-frame.html
正式版:
https://servicewechat.com/小程序appId/6/page-frame.html
三、解决方式。通过nginx做服务器选择。
1、定义一个变量 foo, 配置一个map,把http_referer映射到foo。
map $http_referer $foo {
default "prod";
~^https://servicewechat.com/[^/]+/0/(.*)$ "dev";
~^https://servicewechat.com/[^/]+/devtools/(.*)$ "dev";
}
2、配置服务器。
upstream dev {
server localhost:7777;
}
upstream prod {
server localhost:9999;
}
3、location 中使用 foo变量, 导航到正确的地址。
这里我用add_header把foo变量输出一下,作为测试。
location / {
#set $foo "$http_referer";
add_header wkfoo 'foo: $foo "$http_referer"';
proxy_pass http://$foo;
}
4、测试一下。
curl -H 'Cache-Control: no-cache' -I "https://xxx.xxx.com/prod/xxx?参数1=xxx&参数2=xxx" --referer "https://servicewechat.com/xxx/devtools/page-frame.html"
curl -H 'Cache-Control: no-cache' -I "https://xxx.xxx.com/prod/xxx?参数1=xxx&参数2=xxx" --referer "https://servicewechat.com/xxx/0/page-frame.html"
小程序有无必要设置referer?


好像除非在小程序中打开网页 而且小程序没办法自动带上cookie token 似乎是不能被攻击的?
边栏推荐
- Realization of kaggle cat dog recognition by pytorch
- 云辅助隐私集合求交(Server-Aided PSI)协议介绍:学习
- Arcgis-engine二次开发之空间关系查询与按图形查询
- Is it safe for GF futures to open an account?
- UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation!
- 小芯片chiplet技术杂谈
- 6G显卡显存不足出现CUDA Error:out of memory解决办法
- 使用同花顺手机炒股安全吗?
- Advertising is too "wild", Yoshino "surrenders"
- ABAP essay - material master data interface enhancement - tab enhancement
猜你喜欢

Discuz小鱼游戏风影传说商业GBK+UTF8版模板/DZ游戏网站模板

Consumer finance app user insight in the first quarter of 2022 - a total of 44.79 million people

通过 MQTT 检测对象和传输图像

月薪3万的狗德培训,是不是一门好生意?

资深猎头团队管理者:面试3000顾问,总结组织出8大共性(茅生)

Spug - 轻量级自动化运维平台

网易云“情怀”底牌失守

Azure Kinect DK 实现三维重建 (PC非实时版)

陈云pytorch学习笔记_用50行代码搭建ResNet

Feign通过自定义注解实现路径的转义
随机推荐
2022年第一季度“广州好人”刘磊峰:具有强烈的诚信意识和食品安全意识
Web Worker介绍及使用案例
Aggregation and index optimization of mongodb basic operations
【你真的会用ES吗】ES基础介绍(二)
ABAP随笔-物料主数据界面增强-页签增强
Using the cucumber automated test framework
Zabbix6.0升级指南-数据库如何同步升级?
Spark bug Practice (including bug: classcastexception; connectexception; noclassdeffounderror; runtimeexceptio, etc.)
Livox lidar+apx15 real-time high-precision radar map reproduction and sorting
Stream + Nacos
游戏手机平台简单介绍
跟着存档教程动手学RNAseq分析(四):使用DESeq2进行DE分析的QC方法
Is it safe to use flush mobile phones to speculate in stocks?
第一性原理(最优解理论)
[electron] 基础学习
Advertising is too "wild", Yoshino "surrenders"
NDSS 2022 接收的列表
Summary of various loams (laser SLAM)
SQL Server 2016详细安装教程(附注册码和资源)
使用同花顺手机炒股安全吗?