银联支付
进行支付
public Result getOrder(Integer pid,Integer shopId){
Map<String, String> contentData=new HashMap<String, String>();
contentData.put("version", Config.version); //版本号 全渠道默认值
contentData.put("encoding", Config.encoding); //字符集编码 可以使用UTF-8,GBK两种方式
contentData.put("signMethod", "01"); //签名方法 目前只支持01:RSA方式证书加密
contentData.put("txnType", "01"); //交易类型 01:消费
contentData.put("txnSubType", "01"); //交易子类 01:消费
contentData.put("bizType", "000201"); //填写000201
contentData.put("channelType", "08"); //渠道类型 08手机
contentData.put("merId", merId); //商户号码,请改成自己申请的商户号或者open上注册得来的777商户号测试
contentData.put("accessType", "0"); //接入类型,商户接入填0 ,不需修改(0:直连商户, 1: 收单机构 2:平台商户)
contentData.put("orderId", orderId); //商户订单号,8-40位数字字母,不能含“-”或“_”,可以自行定制规则
contentData.put("txnTime", txnTime); //订单发送时间,取系统时间,格式为YYYYMMDDhhmmss,必须取当前时间,否则会报txnTime无效
contentData.put("accType", "01"); //账号类型 01:银行卡02:存折03:IC卡帐号类型(卡介质)
contentData.put("txnAmt", txnAmt); //交易金额 单位为分
contentData.put("currencyCode", "156"); //境内商户固定
contentData.put("backUrl", Config.backUrl); //回调URL,必须是外网接口
Map<String, String> reqData = AcpService.sign(contentData,Config.encoding);
String requestAppUrl = SDKConfig.getConfig().getAppRequestUrl();
Map<String, String> rspData = AcpService.post(reqData,requestAppUrl,Config.encoding);
String tn=null;//流水号
if(!rspData.isEmpty()){
if(AcpService.validate(rspData, Config.encoding)){
LogUtil.writeLog("验证签名成功");
String respCode = rspData.get("respCode") ;
if(("00").equals(respCode)){
tn = rspData.get("tn");
}
}
}else{
//未返回正确的http状态
}
if(tn==null)
throw new BuzException(-1,"失败,请重试");
return new Result(200,tn);
}
回调银联
private Map<String, String> getAllRequestParamStream(HttpServletRequest request) {
Map<String, String> res = new HashMap<String, String>();
try {
String notifyStr = new String(IOUtils.toByteArray(request.getInputStream()),
Config.encoding);
String[] kvs = notifyStr.split("&");
for (String kv : kvs) {
String[] tmp = kv.split("=");
if (tmp.length >= 2) {
String key = tmp[0];
String value = URLDecoder.decode(tmp[1], Config.encoding);
res.put(key, value);
}
}
} catch (UnsupportedEncodingException e) {
LogUtil.writeLog("getAllRequestParamStream.UnsupportedEncodingException error: " + e.getClass() + ":"
+ e.getMessage());
} catch (IOException e) {
LogUtil.writeLog("getAllRequestParamStream.IOException error: " + e.getClass() + ":" + e.getMessage());
}
return res;
}