jdbc配置文件-需替換真實的參數(shù)
// A code block
#全民付移動c掃b 接口公共參數(shù)配置-------------------------------------------------------
#銀商平臺接口地址
url=https://qr-test2.chinaums.com/netpay-route-server/api/
#商戶號
mid=898340149000***
#終端號
tid=88880***
#機構商戶號
instMid=QRPAYDEFA***
#來源系統(tǒng)
msgSrc=WWW.TEST.COM
#通訊秘鑰
key=fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW*****
#全民付移動c掃b 獲取二維碼接口參數(shù)配置---------------------------------------------------
#消息類型:獲取二維碼
msgType_getQRCode=bills.getQRCode
#全民付移動c掃b 賬單查詢接口參數(shù)配置------------------------------------------------------
#消息類型:賬單查詢
msgType_query=bills.query
#全民付移動c掃b 訂單退款接口參數(shù)配置------------------------------------------------------
#消息類型:訂單退款
msgType_refund=bills.refund
#全民付移動c掃b 根據(jù)商戶終端號查詢此臺終端最后一筆詳單情況 接口參數(shù)配置------------------------------------------------------
#消息類型:根據(jù)商戶終端號查詢此臺終端最后一筆詳單情況
msgType_queryLastQRCode=bills.queryLastQRCode
#全民付移動c掃b 查詢二維碼靜態(tài)信息 接口參數(shù)配置------------------------------------------------------
#消息類型:查詢二維碼靜態(tài)信息
msgType_queryQRCodeInfo=bills.queryQRCodeInfo
#全民付移動c掃b 關閉二維碼 接口參數(shù)配置------------------------------------------------------
#消息類型:關閉二維碼
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 = "銀聯(lián)支付")
@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 = "賬單號(四位數(shù)字)") @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 = "請求系統(tǒng)預留字段") @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 = "網(wǎng)頁跳轉地址") @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 = "系統(tǒng)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 = "花唄分期數(shù)") @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);
// 是否要在商戶系統(tǒng)下單,看商戶需求 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;
}
// // 暫未使用:請求轉發(fā),用戶端掃碼時 二維碼鏈接對應該方法,并由該方法轉發(fā)至銀商平臺
// @RequestMapping(value = "/sendBillQRCode", method = RequestMethod.GET)
// public String sendBillQRCode(HttpServletRequest request, HttpServletResponse response)
// {
// // 接受參數(shù)
// 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("請求參數(shù)對象:" + 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"));
// 是否要在商戶系統(tǒng)下單,看商戶需求 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("請求參數(shù)對象:"+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);
// 是否要在商戶系統(tǒng)下單,看商戶需求 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("請求參數(shù)對象:" + 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);
// 是否要在商戶系統(tǒng)下單,看商戶需求 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;
}
// 根據(jù)商戶終端號查詢此臺終端最后一筆詳單情況
@ResponseBody
@RequestMapping(value = "/queryLastQRCode", method = RequestMethod.POST)
@ApiOperation(value = "根據(jù)商戶終端號查詢此臺終端最后一筆詳單情況", notes = "根據(jù)商戶終端號查詢此臺終端最后一筆詳單情況", 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;
}
// 查詢二維碼靜態(tài)信息接口
@ResponseBody
@RequestMapping(value = "/queryQRCodeInfo", method = RequestMethod.POST)
@ApiOperation(value = "查詢二維碼靜態(tài)信息", notes = "查詢二維碼靜態(tài)信息", 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("請求參數(shù)對象:" + 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
{
/** * 向銀聯(lián)發(fā)送請求
* * @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
{
// 讀取資源配置參數(shù)
@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");
// 發(fā)送POST請求參數(shù)
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", "調用銀商接口出現(xiàn)異常:" + e.toString());
resultStr = JSONObject.fromObject(resultMap).toString();
return resultStr;
} finally
{
if (out != null)
{
out.close();
}
httpURLConnection.disconnect();
}
System.out.println("resultStr:" + resultStr);
return resultStr;
}
}