URLEncoder转码问题

URLEncoder转码问题2019独角兽企业重金招聘Python工程师标准>>>…

大家好,又见面了,我是你们的朋友全栈君。

场景描述:在与前端对接口,该请求需要调用别的渠道的业务,流程如下

1、前端页面->Controller->调用健康险页面->Controller->前端页面

该请求通过get请求进行传参数,请求样例

https://test1-life.pingan.com/health/healthNotify?failBackUrl=https://test1-life.pingan.com/ilifecore/productMall/loading.html?productId=8000000241&channelCode=XCX00001&productCode=00001&actionType=underwrite&actionResult=2&successBackUrl=https://test1-life.pingan.com/ilifecore/productMall/loading.html?channelCode=XCX00001&productCode=00001&productId=8000000241&actionType=underwrite&actionResult=1&outChannelOrderId=30180000000001226447&productId=8000000241&platformSerialNo=20180820092030575
 

前端进行encodeURIComponent 进行编码:

https://test1-life.pingan.com/health/healthNotify?failBackUrl=https%3A%2F%2Ftest1-life.pingan.com%2Filifecore%2FproductMall%2Floading.html%3FproductId%3D8000000241%26channelCode%3DXCX00001%26productCode%3D00001%26actionType%3Dunderwrite%26actionResult%3D2&successBackUrl=https%3A%2F%2Ftest1-life.pingan.com%2Filifecore%2FproductMall%2Floading.html%3FchannelCode%3DXCX00001%26productCode%3D00001%26productId%3D8000000241%26actionType%3Dunderwrite%26actionResult%3D1&outChannelOrderId=30180000000001226447&productId=8000000241&platformSerialNo=20180820092030575

转码发送到后台,后台web服务器本身对其进行解码,Controller对参数进行处理

@RequestMapping("/health/healthNotify")
    public void toHealthNotify(final HttpServletRequest request,
    		final HttpServletResponse response) throws Exception {
    	log.info("HealthNotifyController---------toHealthNotify---------start");
    	
    	String productId = LifeUtil.fixHttpRSAndTrim(request.getParameter("productId"));
    	String failBackUrl = LifeUtil.fixHttpRSAndTrim(request.getParameter("failBackUrl"));
    	String successBackUrl = LifeUtil.fixHttpRSAndTrim(request.getParameter("successBackUrl"));
    	String outChannelOrderId = LifeUtil.fixHttpRSAndTrim(request.getParameter("outChannelOrderId"));
    	String platformSerialNo = LifeUtil.fixHttpRSAndTrim(request.getParameter("platformSerialNo"));
    	
    	
    	log.info("HealthNotifyController---sent------"+failBackUrl);
    	
    	log.info("转码后的"+URLEncoder.encode(failBackUrl,"UTF-8"));

    	//入参校验(platformSerialNo)
    	if (LifeUtil.isNull(platformSerialNo))
    		throw new OuterMessageException(ExReturnMeg.EUD0019);
    	
    	//查询平台来源信息
    	ServiceRequest serviceRequest = new ServiceRequest();
    	serviceRequest.setParameter("thId", outChannelOrderId);
    	serviceRequest.setParameter("platformSerialNo", platformSerialNo);
    	serviceRequest.setRequestedServiceID("queryRelationInfoAction");
    	ServiceResponse serviceResponse = new ServiceResponse();
    	serviceResponse = ACDispatcher.dispatchService(serviceRequest, "pafaAC"); 
    	Map model = serviceResponse.getModel();
    	String productID = (String) model.get("productId");
    	
    	// 校验(productId)
    	if(!productId.equals(productID))
    		throw new OuterMessageException(ExReturnMeg.EUD0020);
 	
        /** 注意:下面的这些参数请根据实际情况参考收银台接口文档替换 **/
        Map<String, String> params = new TreeMap<String, String>();
        params.put("outChannelOrderId", outChannelOrderId);
        params.put("channelId", channelId);
        params.put("productId", getHealthProductId(productId));
        params.put("successBackUrl", URLEncoder.encode(request.getScheme()+"://"+request.getServerName()+"/health/backUrl?result=1&callBack="(URLEncoder.encode(successBackUrl,"UTF-8"), "UTF-8"));
        params.put("failBackUrl", URLEncoder.encode(request.getScheme()+"://"+request.getServerName()+"/health/backUrl?result=0&callBack="+ URLEncoder.encode(failBackUrl,"UTF-8"),"UTF-8"));
        params.put("signMethod", signMethod);
        params.put("signature", encryptRequest(createLinkString(params), cyberarkV9Service.getPassword("ilife.health.signKey")));

        log.info("HealthNotifyController----" + aitestURL + "?" + createLinkString(params));
        
        //跳转至智能健告接口
       response.sendRedirect(aitestURL + "?" + createLinkString(params));
        
     
    }

    关键的地方来了 ,但我们组装好参数,发送到健康险 ,健康险页面处理后,会通过health/backUrl 的Controller 把successBackUrl和failBackUrl返回回来,然后我们通过successBackUrl和failBackUrl 调用前端的接口 。

  public void healthNotityCallBack(final HttpServletRequest request,
    		final HttpServletResponse response) throws Exception{
    log
		.info("HealthNotifyController---------callBack---------start");
    
    	String outChannelOrderId  = LifeUtil.fixHttpRSAndTrim(request.getParameter("outChannelOrderId"));
    	String uwMedicalId = LifeUtil.fixHttpRSAndTrim(request.getParameter("uwMedicalId"));
    	String undwrtDecideType = LifeUtil.fixHttpRSAndTrim(request.getParameter("undwrtDecideType"));
    	String exclusiveAgreement = LifeUtil.fixHttpRSAndTrim(request.getParameter("exclusiveAgreement"));
    	String signature = LifeUtil.fixHttpRSAndTrim(request.getParameter("signature"));
    	String signMethod = LifeUtil.fixHttpRSAndTrim(request.getParameter("signMethod"));
    	String callBack = LifeUtil.fixHttpRSAndTrim(request.getParameter("callBack"));
    
    	log.info("HealthNotifyController---cb----"+callBack);
    	//根据thId获取保单信息
    	ServiceRequest serviceRequest1 = new ServiceRequest();
    	serviceRequest1.setParameter("thId", outChannelOrderId);
    	serviceRequest1.setRequestedServiceID("findAppPolicyByThIdAction");
    	ServiceResponse response1 = new ServiceResponse();
    	response1 = ACDispatcher.dispatchService(serviceRequest1, "pafaAC"); 
    	
    	@SuppressWarnings("rawtypes")
		Map model = response1.getModel();
    	AppPolicyDTO appPolicyDTO = (AppPolicyDTO) model.get("appPolicyDTO");  	
    	
    	//保单
    	if(appPolicyDTO==null)
    		throw new OuterMessageException(ExReturnMeg.EUD0000);
    	
    	appPolicyDTO.setResultID(uwMedicalId);
    	appPolicyDTO.setUdwDecide(undwrtDecideType);
    	
    	
    	//更新th表
    	ServiceRequest serviceRequest2 = new ServiceRequest();
    	serviceRequest2.setCurrentRequestObject(appPolicyDTO);
    	serviceRequest2.setRequestedServiceID("updateAppPolicyAction");
    	ServiceResponse response2 = new ServiceResponse();
    	response2 = ACDispatcher.dispatchService(serviceRequest2, "pafaAC"); 
    	
    	
    	Map<String, String> params = new TreeMap<String, String>();
    	params.put("outChannelOrderId", outChannelOrderId );
    	params.put("uwMedicalId", uwMedicalId );
    	params.put("undwrtDecideType", undwrtDecideType );
    	params.put("exclusiveAgreement", exclusiveAgreement );
    	params.put("signature", signature );
    	params.put("signMethod", signMethod );
    	
    	
    	log
		   .info("HealthNotifyController----" + callBack + "?" + createLinkString(params));
    	 
    	//跳转至小雨伞结果界面
    	if(callBack.contains("?")){
        	response.sendRedirect(callBack+"&"+createLinkString(params));
    	}else{
        	response.sendRedirect(callBack+"?"+createLinkString(params));
    	}
    	

    }

 当我们 拿出回调的successBackUrl和failBackUrl的结果的时候,如下:

/wls/applogs/rtlog/ilife-core-stg1DMZ35021/ilife-core-stg1DMZ35021.out:2018-08-20 14:46:00.774 [INFO ] [HealthNotifyController] [215.128.194.20] {T=J0MLM5Kiv3x1ZSaB} HealthNotifyController---cb----https://test1-life.pingan.com/ilifecore/productMall/loading.html?channelCode=XCX00001

successBackUrl和failBackUrl 只是渠道的第一个参数,其他的参数都被kill掉了。

 

经过分析终于找到原因 

在我们进行调用健康险的智能核保的过程中,健康险出了web服务器会进行一次解码的过程,本省的程序应该也会改url进行一次解码,这样就经过了两次解码 

而我们也是进行两个编码 

        params.put("failBackUrl", URLEncoder.encode(request.getScheme()+"://"+request.getServerName()+"/health/backUrl?result=0&callBack="+URLEncoder.encode(failBackUrl,"UTF-8"),"UTF-8"));

 

经过两次编码后的报文是这样的

https%3a%2f%2ftest1-life.pingan.com%2fhealth%2fhealthNotify%3ffailBackUrl%253dhttps%253a%252f%252ftest1-life.pingan.com%252filifecore%252fproductMall%252floading.html%253fproductId%253d8000000241
%2526channelCode%253dXCX00001%2526productCode%253d00001%2526actionType%253dunderwrite%2526actionResult%253d2

而在智能核保系统经过两次解码的结果 

https://test1-life.pingan.com/health/backUrl?failBackUrl=https://test1-life.pingan.com/ilifecore/productMall/loading.html?productId=8000000241&channelCode=XCX00001&productCode=00001&actionType=underwrite&actionResult=2

 

在按照如何的结果返回给我们系统的时候 ,我们在去 failBackUrl 的值的时候 https://test1-life.pingan.com/ilifecore/productMall/loading.html?productId=8000000241

 

导致返回给前端的内容一致不正确,还是对浏览器的机制不够熟练,希望小伙伴引以为戒

 

 

    

 

转载于:https://my.oschina.net/u/198077/blog/1931032

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/150578.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • UE4 slate_ue4渲染动画

    UE4 slate_ue4渲染动画原创文章,转载请注明出处。点击观看下一篇《UE4Slate二用UMG思想去理解Slate》这里写目录标题前言Slate是什么?为什么要了解Slate?提前需要了解的模块(将对Slate学习很有帮助)前言Slate相关文章,使用引擎版本4.25.4源码版.一共11篇文章。网上Slate的文章介绍很少,所以在这里做一下该部分的文章并记录一下。同时也希望能帮助到大家。Slate是什么?一套GUI架构,它是虚幻引擎的UI架构。我们打开编辑器看到的界面,可以说95%以上(高概猜测数值,甚至100.

  • MATLAB对Googlenet模型进行迁移学习

    MATLAB对Googlenet模型进行迁移学习调用MATLAB中的Googlenet工具箱进行迁移学习。%%加载数据clc;closeall;clear;Location=”;%这里输入自己的数据集unzip(‘MerchData.zip’);imds=imageDatastore(‘MerchData’,…%若使用自己的数据集则改为Location(不加单引号)…

  • Java快速入门的六个技巧[通俗易懂]

    Java快速入门的六个技巧[通俗易懂]学习目标:Java入门该学习什么?Java如何快速入门?Java快速入门的六个技巧,帮你顺利入门Java!学习内容:需要掌握:1、掌握静态方法和属性2、重现接口3、学好集合框架4、例外捕捉5、多线程需要理解机理6、了解网络编程学习目录:文章目录学习目标:学习内容:学习目录:一、掌握静态方法和属性二、重现接口三、学好集合框架四、例外捕捉五、多线程需要理解机理六、了解网络编程一、掌握静态方法和属性静态方法和属性用于描述某一类对象群体的特征,而不是对单个对象的特征。Jav

  • 解读Raft(一 算法基础)

    解读Raft(一 算法基础)

  • div滚动条联动「建议收藏」

    div滚动条联动「建议收藏」应用场景:一般是表头和表体,或者是需要联动的div,滚动一个div的滚动条,让另一个div的滚动条也随之滚动到一样的位置//表头<divid=”sc-table-head-div”class=”sc-table-head-div”style=”position:absolute;”> <tableid=”conitor_head”style=”…

  • linux 动态库 静态库_静态库里面包含动态库

    linux 动态库 静态库_静态库里面包含动态库动态库与静态库文件系统补完文件的三个时间acm动态库与静态库动态链接与静态链接静态库文件系统补完文件的三个时间acm我们通过stat指令查看文件信息:[lyl@VM-4-3-centos2022-3-14]$statlog.txtFile:‘log.txt’Size:0 Blocks:0IOBlock:4096regularemptyfileDevice:fd01h/64769d Inode:790871

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号