记得上下班打卡 | git大法好,push需谨慎

Commit 9c322356 authored by 胡佳晨's avatar 胡佳晨

提交 微信退款

parent f436dbe5
...@@ -31,14 +31,11 @@ public class BaseDao implements IBaseDao { ...@@ -31,14 +31,11 @@ public class BaseDao implements IBaseDao {
@Override @Override
public Boolean batchSql(final String sql, final LinkedList<Object[]> values) { public Boolean batchSql(final String sql, final LinkedList<Object[]> values) {
TransactionCallback<Boolean> callback = new TransactionCallback<Boolean>() { TransactionCallback<Boolean> callback = transactionStatus -> {
@Override if (values.size() > 0) {
public Boolean doInTransaction(final TransactionStatus transactionStatus) { int[] ints = jdbcTemplate.batchUpdate(sql, values);
if (values.size() > 0) {
int[] ints = jdbcTemplate.batchUpdate(sql, values);
}
return true;
} }
return true;
}; };
try { try {
TransactionTemplate tt = new TransactionTemplate(transactionManager); TransactionTemplate tt = new TransactionTemplate(transactionManager);
...@@ -53,31 +50,24 @@ public class BaseDao implements IBaseDao { ...@@ -53,31 +50,24 @@ public class BaseDao implements IBaseDao {
public Boolean batchSqls(final LinkedList<String> sql, public Boolean batchSqls(final LinkedList<String> sql,
final LinkedList<Object[]>... values) { final LinkedList<Object[]>... values) {
try { try {
TransactionCallback<Boolean> callback = new TransactionCallback<Boolean>() { TransactionCallback<Boolean> callback = transactionStatus -> {
@Override int i = 0;
public Boolean doInTransaction(final TransactionStatus transactionStatus) { for (LinkedList<Object[]> o : values) {
int i = 0; if (sql.size() < i + 1) {
for (LinkedList<Object[]> o : values) { break;
if (sql.size() < i + 1) { }
break; if (!o.isEmpty()) {
} jdbcTemplate.batchUpdate(sql.get(i), o);
if (!o.isEmpty()) {
jdbcTemplate.batchUpdate(sql.get(i), o);
}
i++;
} }
return true; i++;
} }
return true;
}; };
TransactionTemplate tt = new TransactionTemplate(transactionManager); TransactionTemplate tt = new TransactionTemplate(transactionManager);
return tt.execute(callback); return tt.execute(callback);
} catch (Exception ex) { } catch (Exception ex) {
// if (ex instanceof LiquidnetServiceException) {
// log.error("###Error.Code:{} - {}", ((LiquidnetServiceException) ex).getCode(), ex.getMessage());
// } else {
log.error("###Error.Sqls:{}\nParameters:{},Ex:{}", JsonUtils.toJson(sql), JsonUtils.toJson(values), ex.getMessage()); log.error("###Error.Sqls:{}\nParameters:{},Ex:{}", JsonUtils.toJson(sql), JsonUtils.toJson(values), ex.getMessage());
// }
return false; return false;
} }
} }
...@@ -85,14 +75,11 @@ public class BaseDao implements IBaseDao { ...@@ -85,14 +75,11 @@ public class BaseDao implements IBaseDao {
@Override @Override
public Boolean batchSqlNoArgs(final LinkedList<String> sql) { public Boolean batchSqlNoArgs(final LinkedList<String> sql) {
try { try {
TransactionCallback<Boolean> callback = new TransactionCallback<Boolean>() { TransactionCallback<Boolean> callback = transactionStatus -> {
@Override for (String o : sql) {
public Boolean doInTransaction(final TransactionStatus transactionStatus) { jdbcTemplate.execute(o);
for (String o : sql) {
jdbcTemplate.execute(o);
}
return true;
} }
return true;
}; };
TransactionTemplate tt = new TransactionTemplate(transactionManager); TransactionTemplate tt = new TransactionTemplate(transactionManager);
...@@ -115,18 +102,14 @@ public class BaseDao implements IBaseDao { ...@@ -115,18 +102,14 @@ public class BaseDao implements IBaseDao {
final Object[] innerO = param; final Object[] innerO = param;
KeyHolder keyHolder = new GeneratedKeyHolder(); KeyHolder keyHolder = new GeneratedKeyHolder();
try { try {
jdbcTemplate.update(new PreparedStatementCreator() { jdbcTemplate.update(con -> {
@Override PreparedStatement ps = con.prepareStatement(innersql,
public PreparedStatement createPreparedStatement(final Connection con) Statement.RETURN_GENERATED_KEYS);
throws SQLException { for (int i = 0; i < innerO.length; i++) {
PreparedStatement ps = con.prepareStatement(innersql, ps.setObject(i + 1, innerO[i]);
Statement.RETURN_GENERATED_KEYS);
for (int i = 0; i < innerO.length; i++) {
ps.setObject(i + 1, innerO[i]);
}
return ps;
} }
return ps;
}, keyHolder); }, keyHolder);
} catch (Exception e) { } catch (Exception e) {
log.error("###\nSQL.Preparing:{}\nParameters:{}", sql, JsonUtils.toJson(param), e); log.error("###\nSQL.Preparing:{}\nParameters:{}", sql, JsonUtils.toJson(param), e);
......
...@@ -26,100 +26,72 @@ import java.io.IOException; ...@@ -26,100 +26,72 @@ import java.io.IOException;
@Slf4j @Slf4j
@Component @Component
public class ConsumerAdamUCenterProcessor { public class ConsumerAdamUCenterProcessor {
@Resource // @Resource
IBaseDao baseDao; // IBaseDao baseDao;
//
// @RabbitListener(bindings = @QueueBinding( // private void consumerSqlDaoHandler(Message msg, Channel channel) {
// exchange = @Exchange(MQConst.EXCHANGES_LIQUIDNET_SQL), key = MQConst.ROUTING_KEY_SQL, // MessageProperties properties = msg.getMessageProperties();
// value = @Queue(MQConst.QUEUES_SQL_MAIN) // String consumerQueue = properties.getConsumerQueue();
// )) // long deliveryTag = properties.getDeliveryTag();
//// @RabbitListener(queues = MQConst.QUEUES_SQL_MAIN) // log.info("CONSUMER SQL ==> [consumerQueue:{},deliveryTag:{}]", consumerQueue, deliveryTag);
// public void consumerSql(Message msg, Channel channel) {
// SqlMapping.SqlMessage sqlMessage = JsonUtils.fromJson(new String(msg.getBody()), SqlMapping.SqlMessage.class); // SqlMapping.SqlMessage sqlMessage = JsonUtils.fromJson(new String(msg.getBody()), SqlMapping.SqlMessage.class);
// log.debug("CONSUMER SQL ==> Preparing:{}", JsonUtils.toJson(sqlMessage.getSqls())); // log.debug("CONSUMER SQL ==> Preparing:{}", JsonUtils.toJson(sqlMessage.getSqls()));
// log.debug("CONSUMER SQL ==> Parameters:{}", JsonUtils.toJson(sqlMessage.getArgs())); // log.debug("CONSUMER SQL ==> Parameters:{}", JsonUtils.toJson(sqlMessage.getArgs()));
//
// try { // try {
// Boolean rstBatchSqls = baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs()); // Boolean rstBatchSqls = baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs());
// log.debug("CONSUMER SQL result of execution:{}", rstBatchSqls); // log.debug("CONSUMER SQL result of execution:{}", rstBatchSqls);
// if (rstBatchSqls) { // if (rstBatchSqls) {
// channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false); // channel.basicAck(deliveryTag, false);
// } else { // } else {
// channel.basicReject(msg.getMessageProperties().getDeliveryTag(), true); // log.warn("###CONSUMER SQL[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, JsonUtils.toJson(sqlMessage));
// } // channel.basicAck(deliveryTag, false);
// } catch (Exception e) {
// log.error("error:CONSUMER SQL:{}", JsonUtils.toJson(sqlMessage), e);
// try {
// channel.basicReject(msg.getMessageProperties().getDeliveryTag(), true);
// } catch (IOException ioException) {
// log.error("error:CONSUMER SQL:basicReject.msg.tag:{}", msg.getMessageProperties().getDeliveryTag(), ioException);
// } // }
// } catch (IOException e) {
// log.error("CONSUMER SQL[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, JsonUtils.toJson(sqlMessage), e);
// } // }
// } // }
//
private void consumerSqlDaoHandler(Message msg, Channel channel) { // /* ================================================================== | 用户注册 */
MessageProperties properties = msg.getMessageProperties(); //
String consumerQueue = properties.getConsumerQueue(); // @RabbitListener(
long deliveryTag = properties.getDeliveryTag(); // bindings = @QueueBinding(
log.info("CONSUMER SQL ==> [consumerQueue:{},deliveryTag:{}]", consumerQueue, deliveryTag); // exchange = @Exchange(MQConst.EX_LNS_SQL_UCENTER),
SqlMapping.SqlMessage sqlMessage = JsonUtils.fromJson(new String(msg.getBody()), SqlMapping.SqlMessage.class); // key = MQConst.RK_SQL_UREGISTER,
log.debug("CONSUMER SQL ==> Preparing:{}", JsonUtils.toJson(sqlMessage.getSqls())); // value = @Queue(MQConst.QUEUES_SQL_UREGISTER)
log.debug("CONSUMER SQL ==> Parameters:{}", JsonUtils.toJson(sqlMessage.getArgs())); // ),
try { // concurrency = "5"
Boolean rstBatchSqls = baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs()); // )
log.debug("CONSUMER SQL result of execution:{}", rstBatchSqls); // public void consumerSqlForURegister(Message msg, Channel channel) {
if (rstBatchSqls) { // this.consumerSqlDaoHandler(msg, channel);
channel.basicAck(deliveryTag, false); // }
} else { //
log.warn("###CONSUMER SQL[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, JsonUtils.toJson(sqlMessage)); // /* ================================================================== | 用户信息 */
channel.basicAck(deliveryTag, false); //
} // @RabbitListener(
} catch (IOException e) { // bindings = @QueueBinding(
log.error("CONSUMER SQL[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, JsonUtils.toJson(sqlMessage), e); // exchange = @Exchange(MQConst.EX_LNS_SQL_UCENTER),
} // key = MQConst.RK_SQL_UCENTER,
} // value = @Queue(MQConst.QUEUES_SQL_UCENTER)
// ),
/* ================================================================== | 用户注册 */ // concurrency = "5"
// )
@RabbitListener( // public void consumerSqlForUCenter(Message msg, Channel channel) {
bindings = @QueueBinding( // this.consumerSqlDaoHandler(msg, channel);
exchange = @Exchange(MQConst.EX_LNS_SQL_UCENTER), // }
key = MQConst.RK_SQL_UREGISTER, //
value = @Queue(MQConst.QUEUES_SQL_UREGISTER) // /* ================================================================== | 会员购买 */
), //
concurrency = "5" // @RabbitListener(
) // bindings = @QueueBinding(
public void consumerSqlForURegister(Message msg, Channel channel) { // exchange = @Exchange(MQConst.EX_LNS_SQL_UCENTER),
this.consumerSqlDaoHandler(msg, channel); // key = MQConst.RK_SQL_UMEMBER,
} // value = @Queue(MQConst.QUEUES_SQL_UMEMBER)
// ),
/* ================================================================== | 用户信息 */ // concurrency = "5"
// )
@RabbitListener( // public void consumerSqlForUMember(Message msg, Channel channel) {
bindings = @QueueBinding( // this.consumerSqlDaoHandler(msg, channel);
exchange = @Exchange(MQConst.EX_LNS_SQL_UCENTER), // }
key = MQConst.RK_SQL_UCENTER,
value = @Queue(MQConst.QUEUES_SQL_UCENTER)
),
concurrency = "5"
)
public void consumerSqlForUCenter(Message msg, Channel channel) {
this.consumerSqlDaoHandler(msg, channel);
}
/* ================================================================== | 会员购买 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SQL_UCENTER),
key = MQConst.RK_SQL_UMEMBER,
value = @Queue(MQConst.QUEUES_SQL_UMEMBER)
),
concurrency = "5"
)
public void consumerSqlForUMember(Message msg, Channel channel) {
this.consumerSqlDaoHandler(msg, channel);
}
/* ================================================================== | */ /* ================================================================== | */
} }
package com.liquidnet.service.dragon.service.impl; package com.liquidnet.service.dragon.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeRefundRequest; import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeRefundResponse; import com.alipay.api.response.AlipayTradeRefundResponse;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -19,6 +17,7 @@ import com.liquidnet.service.dragon.service.IDragonOrderRefundsService; ...@@ -19,6 +17,7 @@ import com.liquidnet.service.dragon.service.IDragonOrderRefundsService;
import com.liquidnet.service.dragon.utils.PayAlipayUtils; import com.liquidnet.service.dragon.utils.PayAlipayUtils;
import com.liquidnet.service.dragon.utils.PayWepayUtils; import com.liquidnet.service.dragon.utils.PayWepayUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
...@@ -32,8 +31,7 @@ import org.springframework.stereotype.Service; ...@@ -32,8 +31,7 @@ import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap; import java.util.*;
import java.util.LinkedList;
@Slf4j @Slf4j
@Service @Service
...@@ -45,33 +43,39 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -45,33 +43,39 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
@Override @Override
public void sendRedisQueue() { public void sendRedisQueue() {
try { try {
PayWepayUtils payWepayUtils = new PayWepayUtils(); // PayWepayUtils payWepayUtils = new PayWepayUtils();
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi");
httpPost.addHeader("Accept", "application/json"); String nonceStr = PayWepayUtils.getInstance().getNonceStr();
httpPost.addHeader("Content-type", "application/json; charset=utf-8"); SortedMap<Object, Object> parameters = new TreeMap<>();
parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantId());
ByteArrayOutputStream bos = new ByteArrayOutputStream(); parameters.put("appid", PayWepayUtils.getInstance().getAppId());
ObjectMapper objectMapper = new ObjectMapper(); parameters.put("nonce_str", nonceStr);
parameters.put("out_refund_no", "20210710140233163870197466289T");
ObjectNode rootNode = objectMapper.createObjectNode(); parameters.put("out_trade_no", "20210710140233163870197466289P");
rootNode.put("mchid", "1551961491") parameters.put("refund_fee", "1");
.put("appid", "wx3498304dda39c5a1") parameters.put("total_fee", "1");
.put("description", "Image形象店-深圳腾大-QQ公仔") parameters.put("notify_url", "https://www.baidu.com");
.put("notify_url", "https://www.weixin.qq.com/wxpay/pay.php") parameters.put("refund_desc", "测试退款");
.put("out_trade_no", "1217752501201407033233368018"); String sign = PayWepayUtils.getInstance().createSign(parameters);
rootNode.putObject("amount") parameters.put("sign", sign);
.put("total", 1); String data = PayWepayUtils.getInstance().getRequestXml(parameters);
rootNode.putObject("payer")
.put("openid", "oUpkkuHUgiyTYE4ZU8Y5Sga-znWQ");
objectMapper.writeValue(bos, rootNode);
httpPost.setEntity(new StringEntity(bos.toString("UTF-8"), "UTF-8"));
CloseableHttpResponse response = payWepayUtils.getHttpClient().execute(httpPost);
String bodyAsString = EntityUtils.toString(response.getEntity());
System.out.println(bodyAsString);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = PayWepayUtils.getInstance().getHttpClient().execute(httpost);
try {
HttpEntity entity = response.getEntity();
//接受到返回信息
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
System.out.println(jsonStr);
} finally {
response.close();
}
} finally {
PayWepayUtils.getInstance().getHttpClient().close();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -127,7 +131,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -127,7 +131,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
"\"out_request_no\":\"" + refundCode + "\"," + "\"out_request_no\":\"" + refundCode + "\"," +
"\"refund_reason\":\"" + reason + "\"," + "\"refund_reason\":\"" + reason + "\"," +
"\"refund_amount\":\"" + price.doubleValue() + "\"}"); //设置业务参数 "\"refund_amount\":\"" + price.doubleValue() + "\"}"); //设置业务参数
AlipayTradeRefundResponse response = PayAlipayUtils.getHttpClient().execute(request);//通过alipayClient调用API,获得对应的response类 AlipayTradeRefundResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);//通过alipayClient调用API,获得对应的response类
System.out.print(response.getBody()); System.out.print(response.getBody());
if (response.getFundChange().equals("N") || response.getFundChange() == null) { if (response.getFundChange().equals("N") || response.getFundChange() == null) {
try { try {
......
...@@ -21,24 +21,24 @@ import java.net.URL; ...@@ -21,24 +21,24 @@ import java.net.URL;
import java.security.PrivateKey; import java.security.PrivateKey;
public class PayAlipayUtils { public class PayAlipayUtils {
private static AlipayClient httpClient = null;
private static PayAlipayUtils instance = new PayAlipayUtils(); private static PayAlipayUtils instance = new PayAlipayUtils();
private static String appId = "2019082866535131"; private AlipayClient httpClient = null;
private static String merchant_pub_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmePaETscydypY3rV4mXa8MtcQIL5zjP1KxdusNkHpePeU61hAZxKn0Z8pDB1wNaTK72wgEWaORXeRp4YTbf4usHlW562Pe5wdiSutb3iT6EMJ5eBD4HLI9wWDgYBtwfHwS5JJFhf0eptP4R1XluLiMhmMynLwJvHepgkVrS3mN+jmoPRmKFhZHGIYDoWypBMbUKiFHWiToHK1n0NYHHIi4WgK2wt4Wj7nexQGD69W7ofRCirYmz35c/cNFUA1lqzOEKu2z7PpjA6jQV2GJolnJ4xXPJ8Dpgp4g/dgsGqRydlmFqZD71i/pDDpF0RfRKHL+WhWVhI1hqe6jLtvJE+zQIDAQAB"; private final String appId = "2019082866535131";
private static String merchant_private_key = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCArhnBTpcAww8wSYBTwGp6oBvenzCCYFrugERgxJDZ7YnBZ3ZdiAaHjJ9PI0WymkpDr27FSg9czVbiH7G91zPq+8s9onrZi/l6cBZ2VjrwQ9BQPN2a8zHy8D6BfoKEV+PIicGz6hNPA7lgf04NgsXeWjeXnYD/IBTLZmnCxB2sPYo/0EN32mlSG9snO63HlPkoqn8ycw71a1cBrlQ+Y22fFnJAk/vrGoou8E0UHfL5zVE/up+ToOYW/eOKMFL/DSceCy32t9Za0RmpV3i2E9s8gBDewzT10Yf4+4mPUiTR6AhcLjqafAy2IaKPK57WZ6cGF9cGs9yq8bSTRpeNC4alAgMBAAECggEAH0Ms+qvPP94j6IVS6gYLWHNhkfp23JXwQZVkB2Z6EpgFKbmrJhoQDAp8Acv9+OBHPp52ePP/O3qfqxwsIIUSFfrKa9T3p7a8C6UDsAhPFWRETdobtLN05SK87NUBfImly2i8aKtruXycIveKzPmCfPzKGMmpN1Jh+vCMrUbcNqX8OUcxmhGvJwnQuBW4QEiepzl89Nl91iSwFmxaZoqLaB9lYUKke/z7FDHTpTWpZvtvxlZ0gvMVNLVp9NBNazolQ8eEjBG2PsQGD2cLUbM33mLTz+/VQjzZR3KXu5kQR9MloURILDsdxE1AyA4AkIXd4eMszEjA4Dv6CQK/jjrsgQKBgQDIiCt1OGmV2sqDBSn4nZNH7BzY3Hdnf+qsYUi+TXKhnQaT8XPKWZpKE/AcqsIKnANmO4sX0NL7ACBe7Rl1RcU9Mq5XuHhnkveFBVRRIHindzUfEN0WgdLy23qmJ2N+1i4FigelY0E5T2lojVb7wycAgAc6vflwE+eYf8W3968q0QKBgQCkRgsVCWWNMSLZeB0V9LV3Om2/UPWY/ovadTxAQtxg0Z75V6Wdu8u0hrYaPSeUK2ryaoE6HKgp7U8NiJGzgm2wpj7D2ysrPmhX5+CjiWkDMCuvWytVT7hLqhhLp7frZT39u8VhyfC8lE0xA67gAPsGSl1sBoZPwvvsmNAQ/h6rlQKBgQCtCtw9be2m88M3JnieYhOax8Po2u5qsLZoBBcKqLhXf7ISbhPWNFXwwJ29jxicoR5J1O3lIj09fVFxuLX0Pb3DXn2VksjLz8Wp0vx8eUHEeRis8xdleaf4C68du/WemOHjw8VvUWQSOVWjc/vwiumYA+K5LQAXWAXM0c1jP+e3UQKBgEWY/1z8TDATn0Yvo3MH6FIJSTIDJOqa/bmibdJ0AVZruUS+o4Y+aEGlyUU4n6og8wCdqv5p4b1Rs2pyb/hzy/FJndHw60s495A2x2/B6eHV6Mw0fhl42wYDnKOA/WUX0bnMcgXKPtpGoqWff9mb0L6LhyUbZpAodf95hr2MTIY5AoGBAIyPtYP6jRyR980h/Ud1MS0fBxymjQrR+kg3GWjnw0ZJJ8yFEXxDqLV8uLyXQKc89HGbI0cClWgZBTjfIPJ5U4Gl19Xlwx1SFrdgg5mGUqnMARTg7w1TG5QLSqNhZo2jgBM5FCJRbDUCO/MzLcFhTeGNva9yP7E7gW5/Dott9D7d"; private final String merchant_pub_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmePaETscydypY3rV4mXa8MtcQIL5zjP1KxdusNkHpePeU61hAZxKn0Z8pDB1wNaTK72wgEWaORXeRp4YTbf4usHlW562Pe5wdiSutb3iT6EMJ5eBD4HLI9wWDgYBtwfHwS5JJFhf0eptP4R1XluLiMhmMynLwJvHepgkVrS3mN+jmoPRmKFhZHGIYDoWypBMbUKiFHWiToHK1n0NYHHIi4WgK2wt4Wj7nexQGD69W7ofRCirYmz35c/cNFUA1lqzOEKu2z7PpjA6jQV2GJolnJ4xXPJ8Dpgp4g/dgsGqRydlmFqZD71i/pDDpF0RfRKHL+WhWVhI1hqe6jLtvJE+zQIDAQAB";
private static String sign_type = "RSA2"; private final String merchant_private_key = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCArhnBTpcAww8wSYBTwGp6oBvenzCCYFrugERgxJDZ7YnBZ3ZdiAaHjJ9PI0WymkpDr27FSg9czVbiH7G91zPq+8s9onrZi/l6cBZ2VjrwQ9BQPN2a8zHy8D6BfoKEV+PIicGz6hNPA7lgf04NgsXeWjeXnYD/IBTLZmnCxB2sPYo/0EN32mlSG9snO63HlPkoqn8ycw71a1cBrlQ+Y22fFnJAk/vrGoou8E0UHfL5zVE/up+ToOYW/eOKMFL/DSceCy32t9Za0RmpV3i2E9s8gBDewzT10Yf4+4mPUiTR6AhcLjqafAy2IaKPK57WZ6cGF9cGs9yq8bSTRpeNC4alAgMBAAECggEAH0Ms+qvPP94j6IVS6gYLWHNhkfp23JXwQZVkB2Z6EpgFKbmrJhoQDAp8Acv9+OBHPp52ePP/O3qfqxwsIIUSFfrKa9T3p7a8C6UDsAhPFWRETdobtLN05SK87NUBfImly2i8aKtruXycIveKzPmCfPzKGMmpN1Jh+vCMrUbcNqX8OUcxmhGvJwnQuBW4QEiepzl89Nl91iSwFmxaZoqLaB9lYUKke/z7FDHTpTWpZvtvxlZ0gvMVNLVp9NBNazolQ8eEjBG2PsQGD2cLUbM33mLTz+/VQjzZR3KXu5kQR9MloURILDsdxE1AyA4AkIXd4eMszEjA4Dv6CQK/jjrsgQKBgQDIiCt1OGmV2sqDBSn4nZNH7BzY3Hdnf+qsYUi+TXKhnQaT8XPKWZpKE/AcqsIKnANmO4sX0NL7ACBe7Rl1RcU9Mq5XuHhnkveFBVRRIHindzUfEN0WgdLy23qmJ2N+1i4FigelY0E5T2lojVb7wycAgAc6vflwE+eYf8W3968q0QKBgQCkRgsVCWWNMSLZeB0V9LV3Om2/UPWY/ovadTxAQtxg0Z75V6Wdu8u0hrYaPSeUK2ryaoE6HKgp7U8NiJGzgm2wpj7D2ysrPmhX5+CjiWkDMCuvWytVT7hLqhhLp7frZT39u8VhyfC8lE0xA67gAPsGSl1sBoZPwvvsmNAQ/h6rlQKBgQCtCtw9be2m88M3JnieYhOax8Po2u5qsLZoBBcKqLhXf7ISbhPWNFXwwJ29jxicoR5J1O3lIj09fVFxuLX0Pb3DXn2VksjLz8Wp0vx8eUHEeRis8xdleaf4C68du/WemOHjw8VvUWQSOVWjc/vwiumYA+K5LQAXWAXM0c1jP+e3UQKBgEWY/1z8TDATn0Yvo3MH6FIJSTIDJOqa/bmibdJ0AVZruUS+o4Y+aEGlyUU4n6og8wCdqv5p4b1Rs2pyb/hzy/FJndHw60s495A2x2/B6eHV6Mw0fhl42wYDnKOA/WUX0bnMcgXKPtpGoqWff9mb0L6LhyUbZpAodf95hr2MTIY5AoGBAIyPtYP6jRyR980h/Ud1MS0fBxymjQrR+kg3GWjnw0ZJJ8yFEXxDqLV8uLyXQKc89HGbI0cClWgZBTjfIPJ5U4Gl19Xlwx1SFrdgg5mGUqnMARTg7w1TG5QLSqNhZo2jgBM5FCJRbDUCO/MzLcFhTeGNva9yP7E7gW5/Dott9D7d";
private static String charset = "utf-8"; private final String sign_type = "RSA2";
private static String gatewayUrl = "https://openapi.alipay.com/gateway.do"; private final String charset = "utf-8";
private final String gatewayUrl = "https://openapi.alipay.com/gateway.do";
public PayAlipayUtils() { public PayAlipayUtils() {
} }
private static PayAlipayUtils getInstance() { public static PayAlipayUtils getInstance() {
return instance; return instance;
} }
public static AlipayClient getHttpClient() { public AlipayClient getHttpClient() {
if(httpClient == null){ if(httpClient == null){
httpClient = new DefaultAlipayClient(gatewayUrl, appId, merchant_private_key, "json", charset, httpClient = new DefaultAlipayClient(gatewayUrl, appId, merchant_private_key, "json", charset,
merchant_pub_key, sign_type); merchant_pub_key, sign_type);
......
package com.liquidnet.service.dragon.utils; package com.liquidnet.service.dragon.utils;
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder; import com.alipay.api.internal.util.file.IOUtils;
import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier; import com.liquidnet.commons.lang.util.MD5Utils;
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner; import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils; import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import java.io.FileInputStream; import javax.net.ssl.SSLContext;
import java.net.URL; import java.io.ByteArrayInputStream;
import java.security.PrivateKey; import java.io.InputStream;
import java.security.KeyStore;
import java.util.*;
public class PayWepayUtils { public class PayWepayUtils {
private CloseableHttpClient httpClient; private CloseableHttpClient httpClient;
// private static PayUtils instance = new PayUtils(); private static PayWepayUtils instance = new PayWepayUtils();
private final String merchantId = "1551961491";
private final String appId = "wx3498304dda39c5a1";
private final String parentKey = "itIuO65O9yKmemOu3S8g1S4orqvCGwXK";
private String merchantId = "1551961491";
private String merchantSerialNumber = "6D25ECC819EAE0BCEA7DB18F143F0752431D9295";
private String appId = "wx3498304dda39c5a1";
public PayWepayUtils() { public PayWepayUtils() {
System.out.println("1"); }
try {
URL path = PayWepayUtils.class.getClassLoader().getResource("payCert/wepay/wepay_apiclient_key.pem");
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(
new FileInputStream(path.getPath())
);
CloseableHttpClient httpClientTemp = WechatPayHttpClientBuilder.create() public static PayWepayUtils getInstance() {
.withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey) return instance;
.withValidator(response -> true) // NOTE: 设置一个空的应答签名验证器,**不要**用在业务请求 }
.build();
URIBuilder uriBuilder = new URIBuilder("https://api.mch.weixin.qq.com/v3/certificates");
HttpGet httpGet = new HttpGet(uriBuilder.build());
httpGet.addHeader("Accept", "application/json");
CloseableHttpResponse response = httpClientTemp.execute(httpGet);
String bodyAsString = EntityUtils.toString(response.getEntity());
AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier( public String getAppId() {
new WechatPay2Credentials(merchantId, new PrivateKeySigner(merchantSerialNumber, merchantPrivateKey)), return appId;
bodyAsString.getBytes("utf-8")); }
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create() public String getMerchantId() {
.withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey) return merchantId;
.withValidator(new WechatPay2Validator(verifier)); }
public CloseableHttpClient getHttpClient() {
try {
if (httpClient == null) {
InputStream certStream = PayWepayUtils.class.getClassLoader().getResourceAsStream("payCert/wepay/wepay_apiclient_cert.p12");
byte[] certData = IOUtils.toByteArray(certStream);
certStream.read(certData);
certStream.close();
httpClient = builder.build(); KeyStore keyStore = KeyStore.getInstance("PKCS12");
ByteArrayInputStream inputStream = new ByteArrayInputStream(certData);
try {
keyStore.load(inputStream, merchantId.toCharArray());
} finally {
inputStream.close();
}
SSLContext sslcontext = SSLContexts.custom()
.loadKeyMaterial(keyStore, merchantId.toCharArray())
.build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return httpClient;
} }
// private static PayUtils getInstance() { //生成随机字符串nonce_str
// return instance; public String getNonceStr() {
// } String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 32; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
}
public String createSign(SortedMap<Object, Object> parameters) {
StringBuffer sb = new StringBuffer();
Set es = parameters.entrySet();//所有参与传参的参数按照accsii排序(升序)
Iterator it = es.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String k = (String) entry.getKey();
Object v = entry.getValue();
if (null != v && !"".equals(v)
&& !"sign".equals(k) && !"key".equals(k)) {
sb.append(k + "=" + v + "&");
}
}
sb.append("key=" + parentKey);
return MD5Utils.md5(sb.toString()).toUpperCase();
}
public CloseableHttpClient getHttpClient() { public String getRequestXml(SortedMap<Object, Object> parameters) {
return httpClient; StringBuffer sb = new StringBuffer();
sb.append("<xml>");
Set es = parameters.entrySet();
Iterator it = es.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String k = (String) entry.getKey();
String v = (String) entry.getValue();
if ("attach".equalsIgnoreCase(k) || "body".equalsIgnoreCase(k) || "sign".equalsIgnoreCase(k)) {
sb.append("<" + k + ">" + "<![CDATA[" + v + "]]></" + k + ">");
} else {
sb.append("<" + k + ">" + v + "</" + k + ">");
}
}
sb.append("</xml>");
return sb.toString();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment