在农行掌银的授权跳转URL中地址是这个样子的:
https://www.abchina.com/luascript/oauthLogin/{\"client_id\":\"abc8293290\",\"redirect_uri\":\"http://localhost:9000/callback\",\"state\":\"123\",\"scope\":\"openid,phone,mreginfo,reglvl\",\"response_type\":\"code\"}
使用方式:
response.sendRedirect('https://www.abchina.com/luascript/oauthLogin/{\"client_id\":\"abc8293290\",\"redirect_uri\":\"http://localhost:9000/callback\",\"state\":\"123\",\"scope\":\"openid,phone,mreginfo,reglvl\",\"response_type\":\"code\"}')
在这种使用方式中农行的服务端是如何接收的?
以这种方式进行本地测试却发现直接返回404,因为地址被json中的“/”截断了
import json
str = 'https://www.abchina.com/luascript/oauthLogin/{\"client_id\":\"abc8293290\",\"redirect_uri\":\"http://localhost:9000/callback\",\"state\":\"123\",\"scope\":\"openid,phone,mreginfo,reglvl\",\"response_type\":\"code\"}'
str_2 = str.replace('https://www.abchina.com/luascript/oauthLogin/','')
print(json.loads(str_2))
#打印的内容{'client_id': 'abc8293290', 'redirect_uri': 'http://localhost:9000/callback', 'state': '123', 'scope': 'openid,phone,mreginfo,reglvl', 'response_type': 'code'}
#语言不通原理相通的,第一步替换可以用正则也可以直接这样替换,看你iurl种类多不多
#json格式化一下就好了
json可以放在请求body中
是的,但是现在这种使用方式也是可以的,不太清楚后台是如何接收的
https://www.abchina.com/luascript/oauthLogin/{\"client_id\":\"abc8293290\",\"redirect_uri\":\"http://localhost:9000/callback\",\"state\":\"123\",\"scope\":\"openid,phone,mreginfo,reglvl\",\"response_type\":\"code\"}
urlencode
https://www.abchina.com/luascript/oauthLogin/%7b%5c%22client_id%5c%22%3a%5c%22abc8293290%5c%22%2c%5c%22redirect_uri%5c%22%3a%5c%22http%3a%2f%2flocalhost%3a9000%2fcallback%5c%22%2c%5c%22state%5c%22%3a%5c%22123%5c%22%2c%5c%22scope%5c%22%3a%5c%22openid%2cphone%2cmreginfo%2creglvl%5c%22%2c%5c%22response_type%5c%22%3a%5c%22code%5c%22%7d
如果是在服务端以response.sendRedirect("xxx")这种方式跳转的话这个地址是没有被转码的,而且对方也可以正常响应
自定义路由,或者说自定义url参数,大把组件可以做到
编码两次就可以了,后台对应解码两次。
encodeURIComponent(encodeURIComponent('{"client_id": "abc8293290","redirect_uri": "http://localhost:9000/callback","state": "123","scope": "openid,phone,mreginfo,reglvl","response_type": "code"}'));
对应到前台应该是
var para = encodeURIComponent(encodeURIComponent('{"client_id": "abc8293290","redirect_uri": "http://localhost:9000/callback","state": "123","scope": "openid,phone,mreginfo,reglvl","response_type": "code"}'));
window.location.href='https://www.abchina.com/luascript/oauthLogin/'+para;
后台的话随便取,只不过需要解码两次
@GetMapping(value = "/test/{para}")
public String test1(@PathVariable String para) throws UnsupportedEncodingException {
para = URLDecoder.decode(URLDecoder.decode(para, "UTF-8"),"UTF-8");
System.out.println(para);
return para;
}
如果是在服务端以response.sendRedirect("xxx")这种方式跳转的话这个地址是没有被转码的,而且对方也可以正常响应