| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 测试支付 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ExecutedResult<String> testPay() throws Exception { |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | HttpPost httpPost = new HttpPost("https://test.sumpay.cn/entrance/gateway.htm"); |
| | | List<BasicNameValuePair> pairList = new ArrayList<>(); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("service", "fosun.sumpay.api.orderpay.order.apply"); |
| | | map.put("version","1.0"); |
| | | map.put("format","JSON"); |
| | | map.put("app_id",); |
| | | map.put("timestamp","20250313142521"); |
| | | map.put("terminal_type","api"); |
| | | map.put("mer_no", "200102833852");//商户号 |
| | | map.put("account_type", "01");//付款方账户类型 |
| | | map.put("card_no", AES256("6217007200125513450"));//付款方账户号 |
| | | map.put("real_name", AES256("尹勇"));//付款方账户名 |
| | | //map.put("bank_code","");//银行代码 |
| | | //map.put("id_type","1");//证件类型 |
| | | //map.put("id_no",AES256(""));//证件号码 |
| | | //map.put("notify_url");//商户后台通知URL |
| | | map.put("goods_name", Base64("测试001"));//商品名称 |
| | | map.put("goods_num", "1");//商品数量 |
| | | map.put("goods_price", "0.11");//商品价格 |
| | | map.put("goods_type", "1");//商品类型 |
| | | map.put("order_no", "111111111111111");//订单号 |
| | | map.put("order_amount", "0.11");//订单金额 |
| | | map.put("order_time", "20250313142521");//订单时间 |
| | | map.put("currency", "CNY");//币种 |
| | | // map.put("pay_comments");//附言 |
| | | //map.put("remark");//备注字段 |
| | | Map<String, String> map1 = new HashMap<>(); |
| | | for (Map.Entry<String, String> entry : map.entrySet()) { |
| | | map1.put(entry.getKey(), entry.getValue()); |
| | | } |
| | | //map转换字符串&拼接并排序 |
| | | String keyAndValueStr = getKeyAndValueStr(map); |
| | | //签名处理 |
| | | String msg = signMsg(keyAndValueStr, PRIVATE_KEY, PASSWORD, "UTF-8"); |
| | | map1.put("sign_type","CERT"); |
| | | map1.put("sign",msg); |
| | | |
| | | for(String key:map1.keySet()){ |
| | | pairList.add(new BasicNameValuePair(key,map1.get(key))); |
| | | } |
| | | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "UTF-8"); |
| | | httpPost.setEntity(entity); |
| | | try { |
| | | // 执行请求并获取响应 |
| | | CloseableHttpResponse response = client.execute(httpPost); |
| | | try { |
| | | if(response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){ |
| | | String data=EntityUtils.toString(response.getEntity(),"UTF-8"); |
| | | System.out.println(data); |
| | | }else { |
| | | throw new RuntimeException("接口连接失败"); |
| | | } |
| | | // 处理响应... |
| | | } finally { |
| | | response.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | client.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return ExecutedResult.success(); |
| | | } |
| | | /** |
| | | * 订单支付确认接口 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ExecutedResult<String> confirmPay() throws Exception { |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | HttpPost httpPost = new HttpPost("https://test.sumpay.cn/entrance/gateway.htm"); |
| | | List<BasicNameValuePair> pairList = new ArrayList<>(); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("service", "fosun.sumpay.api.orderpay.order.apply"); |
| | | map.put("version","1.0"); |
| | | map.put("format","JSON"); |
| | | map.put("app_id",); |
| | | map.put("timestamp","20250313142521"); |
| | | map.put("terminal_type","api"); |
| | | map.put("mer_no", "200102833852");//商户号 |
| | | map.put("order_no", "111111111111111");//订单号 |
| | | map.put("serial_no", "");//入账流水号 |
| | | Map<String, String> map1 = new HashMap<>(); |
| | | for (Map.Entry<String, String> entry : map.entrySet()) { |
| | | map1.put(entry.getKey(), entry.getValue()); |
| | | } |
| | | //map转换字符串&拼接并排序 |
| | | String keyAndValueStr = getKeyAndValueStr(map); |
| | | //签名处理 |
| | | String msg = signMsg(keyAndValueStr, PRIVATE_KEY, PASSWORD, "UTF-8"); |
| | | map1.put("sign_type","CERT"); |
| | | map1.put("sign",msg); |
| | | |
| | | for(String key:map1.keySet()){ |
| | | pairList.add(new BasicNameValuePair(key,map1.get(key))); |
| | | } |
| | | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "UTF-8"); |
| | | httpPost.setEntity(entity); |
| | | try { |
| | | // 执行请求并获取响应 |
| | | CloseableHttpResponse response = client.execute(httpPost); |
| | | try { |
| | | if(response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){ |
| | | String data=EntityUtils.toString(response.getEntity(),"UTF-8"); |
| | | System.out.println(data); |
| | | }else { |
| | | throw new RuntimeException("接口连接失败"); |
| | | } |
| | | // 处理响应... |
| | | } finally { |
| | | response.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | client.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return ExecutedResult.success(); |
| | | } |
| | | /** |
| | | * 签名处理 |
| | | * @param privateKeyPath:私钥 |