jdbc配置文件-需替换真实的参数
// A code block
#全民付移动c扫b 接口公共参数配置-------------------------------------------------------
#银商平台接口地址
url=https://qr-test2.chinaums.com/netpay-route-server/api/
#商户号
mid=898340149000***
#终端号
tid=88880***
#机构商户号
instMid=QRPAYDEFA***
#来源系统
msgSrc=WWW.TEST.COM
#通讯秘钥
key=fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW*****
#全民付移动c扫b 获取二维码接口参数配置---------------------------------------------------
#消息类型:获取二维码
msgType_getQRCode=bills.getQRCode
#全民付移动c扫b 账单查询接口参数配置------------------------------------------------------
#消息类型:账单查询
msgType_query=bills.query
#全民付移动c扫b 订单退款接口参数配置------------------------------------------------------
#消息类型:订单退款
msgType_refund=bills.refund
#全民付移动c扫b 根据商户终端号查询此台终端最后一笔详单情况 接口参数配置------------------------------------------------------
#消息类型:根据商户终端号查询此台终端最后一笔详单情况
msgType_queryLastQRCode=bills.queryLastQRCode
#全民付移动c扫b 查询二维码静态信息 接口参数配置------------------------------------------------------
#消息类型:查询二维码静态信息
msgType_queryQRCodeInfo=bills.queryQRCodeInfo
#全民付移动c扫b 关闭二维码 接口参数配置------------------------------------------------------
#消息类型:关闭二维码
msgType_closeQRCode=bills.closeQRCode
Controller
// An highlighted block
package com.kingee.dlaq.lclp.controller;
import static com.kingee.hidp.common.util.CScanBUtil.makeSign;
import java.util.Date;
import java.util.Map;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.kingee.dlaq.lclp.service.CScanBService;
import com.kingee.dlaq.lclp.util.Util;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
/** * @author 张
* @date 2020年7月10日 上午9:13:33
* @Description: C扫B
*/
@Api(value = "/lp", description = "银联支付")
@Controller
@RequestMapping("/lp/CSB")
public class CScanBController
{
@Autowired
private CScanBService cScanBService;
private String mid = "898340149000005";
private String tid = "88880001";
private String key = "fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW2ysRR";
private String msgSrc = "WWW.TEST.COM";
private String instMid = "QRPAYDEFAULT";
// 获取二维码模块
@RequestMapping(value = "/getQrCode", method = RequestMethod.POST)
@ApiOperation(value = "获取二维码页面", notes = "获取二维码页面", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String getQrCode(
// @ApiParam(required = true, name = "departId", value = "部门ID") @RequestParam(value = "departId", required = true) String departId,
// @ApiParam(required = true, name = "billNo", value = "账单号(四位数字)") @RequestParam(value = "billNo", required = false) String billNo,
// @ApiParam(required = false, name = "billDate", value = "账单日期") @RequestParam(value = "billDate", required = false) Date billDate,
@ApiParam(required = true, name = "totalAmount", value = "支付总金额") @RequestParam(value = "totalAmount", required = true) String totalAmount
// @ApiParam(required = false, name = "msgId", value = "消息ID") @RequestParam(value = "msgId", required = false) String msgId,
// @ApiParam(required = false, name = "srcReserve", value = "请求系统预留字段") @RequestParam(value = "srcReserve", required = false) String srcReserve,
// @ApiParam(required = false, name = "billDesc", value = "账单描述") @RequestParam(value = "billDesc", required = false) String billDesc,
// @ApiParam(required = false, name = "divisionFlag", value = "分账标记") @RequestParam(value = "divisionFlag", required = false) Boolean divisionFlag,
// @ApiParam(required = false, name = "platformAmount", value = "平台商户分账金额") @RequestParam(value = "platformAmount", required = false) BigDecimal platformAmount,
// @ApiParam(required = false, name = "goods", value = "商户信息") @RequestParam(value = "goods", required = false) JSON goods,
// @ApiParam(required = false, name = "subOrders", value = "子商户信息") @RequestParam(value = "subOrders", required = false) JSON subOrders,
// @ApiParam(required = false, name = "memberId", value = "会员号") @RequestParam(value = "memberId", required = false) String memberId,
// @ApiParam(required = false, name = "counterNo", value = "桌号、柜台号、房间号") @RequestParam(value = "counterNo", required = false) String counterNo,
// @ApiParam(required = false, name = "expireTime", value = "账单过期时间,为空则不过期") @RequestParam(value = "expireTime", required = false) Date expireTime,
// @ApiParam(required = false, name = "notifyUrl", value = "支付结果通知地址") @RequestParam(value = "notifyUrl", required = false) String notifyUrl,
// @ApiParam(required = false, name = "returnUrl", value = "网页跳转地址") @RequestParam(value = "returnUrl", required = false) String returnUrl,
// @ApiParam(required = false, name = "qrCodeId", value = "二维码ID") @RequestParam(value = "qrCodeId", required = false) String qrCodeId,
// @ApiParam(required = false, name = "systemId", value = "系统ID") @RequestParam(value = "systemId", required = false) String systemId,
// @ApiParam(required = false, name = "secureTransaction", value = "担保交易标识") @RequestParam(value = "secureTransaction", required = false) String secureTransaction,
// @ApiParam(required = false, name = "walletOption", value = "钱包选项") @RequestParam(value = "walletOption", required = false) String walletOption,
// @ApiParam(required = false, name = "name", value = "实名认证姓名") @RequestParam(value = "name", required = false) String name,
// @ApiParam(required = false, name = "mobile", value = "实名认证手机号") @RequestParam(value = "mobile", required = false) String mobile,
// @ApiParam(required = false, name = "certType", value = "实名认证证件类型") @RequestParam(value = "certType", required = false) String certType,
// @ApiParam(required = false, name = "certNo", value = "实名认证证件号") @RequestParam(value = "certNo", required = false) String certNo,
// @ApiParam(required = false, name = "fixBuyer", value = "是否需要实名认证") @RequestParam(value = "fixBuyer", required = false) String fixBuyer,
// @ApiParam(required = false, name = "limitCreditCard ", value = "是否需要限制信用卡支付") @RequestParam(value = "limitCreditCard ", required = false) Boolean limitCreditCard,
// @ApiParam(required = false, name = "payInfoQueryAddr", value = "支付要素查询地址") @RequestParam(value = "payInfoQueryAddr", required = false) String payInfoQueryAddr,
// @ApiParam(required = false, name = "installmentNumber", value = "花呗分期数") @RequestParam(value = "installmentNumber", required = false) String installmentNumber,
// @ApiParam(required = false, name = "asynDivisionFlag", value = "异步分账标记") @RequestParam(value = "asynDivisionFlag", required = false) Boolean asynDivisionFlag
)
{
JSONObject json = new JSONObject();
json.put("mid", mid);
json.put("tid", tid);
json.put("msgType", "bills.getQRCode");
json.put("msgSrc", msgSrc);
json.put("instMid", instMid);
// 是否要在商户系统下单,看商户需求 createBill()
json.put("returnUrl", "http://47.99.194.20/DLAQ/app3/mobile/pay/payResult.html");
json.put("billNo", Util.genMerOrderId("3194"));
json.put("billDate", DateFormatUtils.format(new Date(), "yyyy-MM-dd"));
json.put("totalAmount", totalAmount.toString());
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
json.put("signType", "SHA256");
Map<String, String> paramsMap = Util.jsonToMap(json);
paramsMap.put("sign", makeSign(key, paramsMap));
String strReqJsonStr = JSON.toJSONString(paramsMap);
String string = cScanBService.getQrCode(strReqJsonStr);
// return super.toString(success, "", string);
return string;
}
// // 暂未使用:请求转发,用户端扫码时 二维码链接对应该方法,并由该方法转发至银商平台
// @RequestMapping(value = "/sendBillQRCode", method = RequestMethod.GET)
// public String sendBillQRCode(HttpServletRequest request, HttpServletResponse response)
// {
// // 接受参数
// String billQRCode = request.getParameter("billQRCode");
// try
// {
// response.sendRedirect(billQRCode);
// } catch (IOException e)
// {
// e.printStackTrace();
// }
// return null;
// }
// 二维码更新
@ResponseBody
@RequestMapping(value = "/upDateQrCode", method = RequestMethod.POST)
@ApiOperation(value = "二维码更新", notes = "二维码更新", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String upDateQrCode(
@ApiParam(required = false, name = "walletOption", value = "钱包选项", allowableValues = "SINGLE,MULTIPLE") @RequestParam(value = "walletOption", required = false) String walletOption,
@ApiParam(required = true, name = "qrCodeId", value = "二维码ID") @RequestParam(value = "qrCodeId", required = true) String qrCodeId)
{
// System.out.println("请求参数对象:" + requestParams);
// 组织请求报文
JSONObject json = new JSONObject();
json.put("msgSrc", msgSrc);
json.put("msgType", "bills.updateQRCode");
json.put("mid", mid);
json.put("tid", tid);
json.put("instMid", instMid);
json.put("billNo", Util.genMerOrderId("3194"));
// 是否要在商户系统下单,看商户需求 createBill()
json.put("walletOption", "SINGLE");
json.put("qrCodeId", qrCodeId);
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
json.put("signType", "SHA256");
Map<String, String> paramsMap = Util.jsonToMap(json);
paramsMap.put("sign", makeSign(key, paramsMap));
System.out.println("paramsMap:" + paramsMap);
String strReqJsonStr = JSON.toJSONString(paramsMap);
System.out.println("strReqJsonStr:" + strReqJsonStr);
String string = cScanBService.getQrCode(strReqJsonStr);
return string;
}
// 关闭二维码接口
@ResponseBody
@RequestMapping(value = "/closeQRCode", method = RequestMethod.POST)
@ApiOperation(value = "关闭二维码", notes = "关闭二维码", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String closeQRCode(
@ApiParam(required = true, name = "qrCodeId", value = "二维码ID") @RequestParam(value = "qrCodeId", required = true) String qrCodeId)
{
// 组织请求报文
JSONObject json = new JSONObject();
json.put("msgType", "bills.closeQRCode");
json.put("msgSrc", msgSrc);
json.put("mid", mid);
json.put("tid", tid);
json.put("instMid", instMid);
json.put("qrCodeId", qrCodeId);
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
json.put("signType", "SHA256");
Map<String, String> paramsMap = Util.jsonToMap(json);
paramsMap.put("sign", makeSign(key, paramsMap));
System.out.println("paramsMap:" + paramsMap);
String strReqJsonStr = JSON.toJSONString(paramsMap);
System.out.println("strReqJsonStr:" + strReqJsonStr);
String string = cScanBService.getQrCode(strReqJsonStr);
return string;
}
// 交易退款
@ResponseBody
@RequestMapping(value = "/refund", method = RequestMethod.POST)
@ApiOperation(value = "交易退款", notes = "交易退款", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String refund(
@ApiParam(required = false, name = "billNo", value = "账单号") @RequestParam(value = "billNo", required = false) String billNo,
@ApiParam(required = false, name = "billDate", value = "账单日期") @RequestParam(value = "billDate", required = false) String billDate,
@ApiParam(required = false, name = "refundAmount", value = "要退货的金额") @RequestParam(value = "refundAmount", required = false) String refundAmount)
{
// System.out.println("请求参数对象:"+requestParams);
// 组织请求报文
JSONObject json = new JSONObject();
json.put("mid", mid);
json.put("tid", tid);
json.put("msgType", "bills.refund");
json.put("msgSrc", msgSrc);
json.put("instMid", instMid);
json.put("billNo", billNo);
// 是否要在商户系统下单,看商户需求 createBill()
json.put("billDate", billDate);
json.put("refundAmount", refundAmount);
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
json.put("signType", "SHA256");
Map<String, String> paramsMap = Util.jsonToMap(json);
paramsMap.put("sign", makeSign(key, paramsMap));
System.out.println("paramsMap:" + paramsMap);
String strReqJsonStr = JSON.toJSONString(paramsMap);
System.out.println("strReqJsonStr:" + strReqJsonStr);
String string = cScanBService.getQrCode(strReqJsonStr);
return string;
}
// 账单查询
@ResponseBody
@RequestMapping(value = "/billQuery", method = RequestMethod.POST)
@ApiOperation(value = "账单查询", notes = "账单查询", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String billQuery(
@ApiParam(required = false, name = "billNo", value = "账单号") @RequestParam(value = "billNo", required = false) String billNo,
@ApiParam(required = false, name = "billDate", value = "账单日期") @RequestParam(value = "billDate", required = false) String billDate)
{
// System.out.println("请求参数对象:" + requestParams);
// 组织请求报文
JSONObject json = new JSONObject();
json.put("msgSrc", msgSrc);
json.put("msgType", "bills.query");
json.put("mid", mid);
json.put("tid", tid);
json.put("instMid", instMid);
// 是否要在商户系统下单,看商户需求 createBill()
json.put("billNo", billNo);
json.put("billDate", billDate);
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
json.put("signType", "SHA256");
Map<String, String> paramsMap = Util.jsonToMap(json);
paramsMap.put("sign", makeSign(key, paramsMap));
System.out.println("paramsMap:" + paramsMap);
String strReqJsonStr = JSON.toJSONString(paramsMap);
System.out.println("strReqJsonStr:" + strReqJsonStr);
String string = cScanBService.getQrCode(strReqJsonStr);
return string;
}
// 根据商户终端号查询此台终端最后一笔详单情况
@ResponseBody
@RequestMapping(value = "/queryLastQRCode", method = RequestMethod.POST)
@ApiOperation(value = "根据商户终端号查询此台终端最后一笔详单情况", notes = "根据商户终端号查询此台终端最后一笔详单情况", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String queryLastQRCode()
{
// 组织请求报文
JSONObject json = new JSONObject();
json.put("mid", mid);
json.put("tid", tid);
json.put("msgType", "bills.queryLastQRCode");
json.put("msgSrc", msgSrc);
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
json.put("signType", "SHA256");
Map<String, String> paramsMap = Util.jsonToMap(json);
paramsMap.put("sign", makeSign(key, paramsMap));
System.out.println("paramsMap:" + paramsMap);
String strReqJsonStr = JSON.toJSONString(paramsMap);
System.out.println("strReqJsonStr:" + strReqJsonStr);
String string = cScanBService.getQrCode(strReqJsonStr);
return string;
}
// 查询二维码静态信息接口
@ResponseBody
@RequestMapping(value = "/queryQRCodeInfo", method = RequestMethod.POST)
@ApiOperation(value = "查询二维码静态信息", notes = "查询二维码静态信息", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String queryQRCodeInfo(
@ApiParam(required = true, name = "qrCodeId", value = "终端号") @RequestParam(value = "qrCodeId", required = true) String qrCodeId,
@ApiParam(required = true, name = "msgSrc", value = "消息来源") @RequestParam(value = "msgSrc", required = true) String msgSrc)
{
// 组织请求报文
JSONObject json = new JSONObject();
json.put("msgType", "bills.queryQRCodeInfo");
json.put("msgSrc", msgSrc);
json.put("qrCodeId", qrCodeId);
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
json.put("signType", "SHA256");
Map<String, String> paramsMap = Util.jsonToMap(json);
paramsMap.put("sign", makeSign(key, paramsMap));
System.out.println("paramsMap:" + paramsMap);
String strReqJsonStr = JSON.toJSONString(paramsMap);
System.out.println("strReqJsonStr:" + strReqJsonStr);
String string = cScanBService.getQrCode(strReqJsonStr);
return string;
}
// 模拟对银商平台的支付通知进行验签
// @ResponseBody
// @RequestMapping(value = "/checkSign", method = RequestMethod.POST)
// @ApiOperation(value = "模拟对银商平台的支付通知进行验签", notes = "模拟对银商平台的支付通知进行验签", response = JSON.class, httpMethod = "POST", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
// public String checkSign(
// @ApiParam(required = true, name = "notifyStr", value = "商户号") @RequestParam(value = "notifyStr", required = true) String notifyStr)
// {
// System.out.println("请求参数对象:" + notifyStr);
//
// String resultStr = NotifyUtilTest.makePreStrs(notifyStr);
//
// System.out.println("resultStr:" + resultStr);
// return resultStr;
// }
}
Service
// An highlighted block
/* * Project: D
* Author:
* Company: 高速信息工程技术有限公司
* Created Date: 2020年7月10日
* * Copyright @ 2015 KINGEE.COM – Confidential and Proprietary */
package com.kingee.dlaq.lclp.service;
/** * * @author
* @date 2020年7月10日 上午9:15:14
* @Description:
*/
public interface CScanBService
{
/** * 向银联发送请求
* * @param strReqJsonStr
* @return string
*/
String getQrCode(String strReqJsonStr);
}
ServiceImpl
package com.kingee.dlaq.lclp.service.impl;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.kingee.dlaq.lclp.service.CScanBService;
//import net.sf.json.JSON;
import net.sf.json.JSONObject;
/** * @author
* @date 2020年7月10日 上午9:15:56
* @Description:
*/
@Service
public class CScanBServiceImpl implements CScanBService
{
// 读取资源配置参数
@Value("${url}")
private String APIurl;
/* * (non-Javadoc)
* * @see com.kingee.dlaq.lclp.service.CScanBService#getQrCode(java.lang.String)
*/
@Override
public String getQrCode(String strReqJsonStr)
{
// 调用银商平台获取二维码接口
HttpURLConnection httpURLConnection = null;
BufferedReader in = null;
PrintWriter out = null;
// OutputStreamWriter out = null;
String resultStr = null;
Map<String, String> resultMap = new HashMap<String, String>();
if (!StringUtils.isNotBlank(APIurl))
{
resultMap.put("errCode", "URLFailed");
resultStr = JSONObject.fromObject(resultMap).toString();
return resultStr;
}
try
{
URL url = new URL(APIurl);
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestProperty("Content_Type", "application/json");
httpURLConnection.setRequestProperty("Accept_Charset", "UTF-8");
httpURLConnection.setRequestProperty("contentType", "UTF-8");
// 发送POST请求参数
out = new PrintWriter(httpURLConnection.getOutputStream());
// out = new OutputStreamWriter(httpURLConnection.getOutputStream(),"utf-8");
out.write(strReqJsonStr);
// out.println(strReqJsonStr);
out.flush();
// 读取响应
if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK)
{
StringBuffer content = new StringBuffer();
String tempStr = null;
in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
while ((tempStr = in.readLine()) != null)
{
content.append(tempStr);
}
System.out.println("content:" + content.toString());
// 转换成json对象
com.alibaba.fastjson.JSONObject respJson = JSON.parseObject(content.toString());
String resultCode = respJson.getString("errCode");
resultMap.put("errCode", resultCode);
if (resultCode.equals("SUCCESS"))
{
String billQRCode = (String) respJson.get("billQRCode");
resultMap.put("billQRCode", billQRCode);
resultMap.put("respStr", respJson.toString());
} else
{
resultMap.put("respStr", respJson.toString());
}
resultStr = JSONObject.fromObject(resultMap).toString();
}
} catch (Exception e)
{
e.printStackTrace();
resultMap.put("errCode", "HttpURLException");
resultMap.put("msg", "调用银商接口出现异常:" + e.toString());
resultStr = JSONObject.fromObject(resultMap).toString();
return resultStr;
} finally
{
if (out != null)
{
out.close();
}
httpURLConnection.disconnect();
}
System.out.println("resultStr:" + resultStr);
return resultStr;
}
}