CUP payment (a) apply for the test environment, test and run the demo

1. Register an account

Click to go to CUP payment platform to address open

Register an account

Select Normal user login account

After logging in click through to the merchant Test Center

After entering the product list, select the online payment gateway, and then click operation to integration testing for payment privileges take effect after 10 minutes (if not click here, no permissions will be prompted to pay)

For other products, such as non-payment jump, two-dimensional code and introduce the payment of usage scenarios can referrer business application scenarios product introduction , this article as an example to the online payment gateway

2. Test demo build and run

1. Download the official demo  online payment gateway demo download URL

2. Download the test certificate

Back to the test center> Test parameters> download the specified certificate> stored in native D drive certs directory

Here are four certificate files to download, bearing in mind their own business number 777 at the beginning of the test

There are testing the bottom of the bank card data

3.idea Import demo program

Here import the project according to their actual development environment.

4. Run and access http://127.0.0.1:8081/ACPSample_B2C/

Where merchants and address to test their business number to jump to click submit detailed payment page.

Enter the test account information to complete payment

3. Payment submission process analysis

We enter the demo process

com.unionpay.acp.demo.consume.Form_6_2_FrontConsume class in his post method

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("12345");
		resp.setContentType("text/html; charset="+ DemoBase.encoding);
		
		//前台页面传过来的
		String merId = req.getParameter("merId");
		String txnAmt = req.getParameter("txnAmt");
		String orderId = req.getParameter("orderId");
		String txnTime = req.getParameter("txnTime");
		
		Map<String, String> requestData = new HashMap<String, String>();
		
		/***银联全渠道系统,产品参数,除了encoding自行选择外其他不需修改***/
		requestData.put("version", DemoBase.version);   			  //版本号,全渠道默认值
		requestData.put("encoding", DemoBase.encoding); 			  //字符集编码,可以使用UTF-8,GBK两种方式
		requestData.put("signMethod", SDKConfig.getConfig().getSignMethod()); //签名方法
		requestData.put("txnType", "01");               			  //交易类型 ,01:消费
		requestData.put("txnSubType", "01");            			  //交易子类型, 01:自助消费
		requestData.put("bizType", "000201");           			  //业务类型,B2C网关支付,手机wap支付
		requestData.put("channelType", "07");           			  //渠道类型,这个字段区分B2C网关支付和手机wap支付;07:PC,平板  08:手机
		
		/***商户接入参数***/
		requestData.put("merId", merId);    	          			  //商户号码,请改成自己申请的正式商户号或者open上注册得来的777测试商户号
		requestData.put("accessType", "0");             			  //接入类型,0:直连商户 
		requestData.put("orderId",orderId);             //商户订单号,8-40位数字字母,不能含“-”或“_”,可以自行定制规则		
		requestData.put("txnTime", txnTime);        //订单发送时间,取系统时间,格式为yyyyMMddHHmmss,必须取当前时间,否则会报txnTime无效
		requestData.put("currencyCode", "156");         			  //交易币种(境内商户一般是156 人民币)		
		requestData.put("txnAmt", txnAmt);             			      //交易金额,单位分,不要带小数点
		//requestData.put("reqReserved", "透传字段");        		      //请求方保留域,如需使用请启用即可;透传字段(可以实现商户自定义参数的追踪)本交易的后台通知,对本交易的交易状态查询交易、对账文件中均会原样返回,商户可以按需上传,长度为1-1024个字节。出现&={}[]符号时可能导致查询接口应答报文解析失败,建议尽量只传字母数字并使用|分割,或者可以最外层做一次base64编码(base64编码之后出现的等号不会导致解析失败可以不用管)。		
		
		requestData.put("riskRateInfo", "{commodityName=测试商品名称}");
		
		//前台通知地址 (需设置为外网能访问 http https均可),支付成功后的页面 点击“返回商户”按钮的时候将异步通知报文post到该地址
		//如果想要实现过几秒中自动跳转回商户页面权限,需联系银联业务申请开通自动返回商户权限
		//异步通知参数详见open.unionpay.com帮助中心 下载  产品接口规范  网关支付产品接口规范 消费交易 商户通知
		requestData.put("frontUrl", DemoBase.frontUrl);
		
		//后台通知地址(需设置为【外网】能访问 http https均可),支付成功后银联会自动将异步通知报文post到商户上送的该地址,失败的交易银联不会发送后台通知
		//后台通知参数详见open.unionpay.com帮助中心 下载  产品接口规范  网关支付产品接口规范 消费交易 商户通知
		//注意:1.需设置为外网能访问,否则收不到通知    2.http https均可  3.收单后台通知后需要10秒内返回http200或302状态码 
		//    4.如果银联通知服务器发送通知后10秒内未收到返回状态码或者应答码非http200,那么银联会间隔一段时间再次发送。总共发送5次,每次的间隔时间为0,1,2,4分钟。
		//    5.后台通知地址如果上送了带有?的参数,例如:http://abc/web?a=b&c=d 在后台通知处理程序验证签名之前需要编写逻辑将这些字段去掉再验签,否则将会验签失败
		requestData.put("backUrl", DemoBase.backUrl);

		// 订单超时时间。
		// 超过此时间后,除网银交易外,其他交易银联系统会拒绝受理,提示超时。 跳转银行网银交易如果超时后交易成功,会自动退款,大约5个工作日金额返还到持卡人账户。
		// 此时间建议取支付时的北京时间加15分钟。
		// 超过超时时间调查询接口应答origRespCode不是A6或者00的就可以判断为失败。
		requestData.put("payTimeout", new SimpleDateFormat("yyyyMMddHHmmss").format(new Date().getTime() + 15 * 60 * 1000));
		
		//////////////////////////////////////////////////
		//
		//       报文中特殊用法请查看 PCwap网关跳转支付特殊用法.txt
		//
		//////////////////////////////////////////////////
		
		/**请求参数设置完毕,以下对请求参数进行签名并生成html表单,将表单写入浏览器跳转打开银联页面**/
		Map<String, String> submitFromData = AcpService.sign(requestData,DemoBase.encoding);  //报文中certId,signature的值是在signData方法中获取并自动赋值的,只要证书配置正确即可。
		
		String requestFrontUrl = SDKConfig.getConfig().getFrontRequestUrl();  //获取请求银联的前台地址:对应属性文件acp_sdk.properties文件中的acpsdk.frontTransUrl
		String html = AcpService.createAutoFormHtml(requestFrontUrl, submitFromData,DemoBase.encoding);   //生成自动跳转的Html表单
		
		LogUtil.writeLog("打印请求HTML,此为请求报文,为联调排查问题的依据:"+html);
		//将生成的html写到浏览器中完成自动跳转打开银联支付页面;这里调用signData之后,将html写到浏览器跳转到银联页面之前均不能对html中的表单项的名称和值进行修改,如果修改会导致验签不通过
		resp.getWriter().write(html);

The service parameters encapsulated in the map and then signed, and then spliced ​​into the service data returned html page.

Specific methods are as follows generate html

We found him the business cycle parameters into a hidden input elements, then loaded on a page be submitted by post

Specific submission address is [] profile

acpsdk.frontTransUrl=https://gateway.95516.com/gateway/api/frontTransReq.do

After the test page and submit a final payment of the same jump address

 

 

发布了229 篇原创文章 · 获赞 49 · 访问量 10万+

Guess you like

Origin blog.csdn.net/baiyan3212/article/details/104364683