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

Commit db1716d7 authored by jiangxiulong's avatar jiangxiulong

Merge remote-tracking branch 'origin/dev' into dev

parents b05f1f50 30a9c638
......@@ -3,6 +3,10 @@ package com.liquidnet.service.adam.constant;
public class AdamRedisConst {
public static final String ADAM = "adam:";
public static final String VALID = ADAM.concat("valid:");
public static final String VALID_SMS_CODE_MOBILE = VALID.concat("sms:code:mobile");
public static final String IDENTITY = ADAM.concat("identity:");
public static final String IDENTITY_MOBILE = IDENTITY.concat("mobile:");
......@@ -44,7 +48,7 @@ public class AdamRedisConst {
public static final String LOCK_KEY_UMEMBER_NO = "adam:lk:member:no";
// // // // // // // // // //
public static final String LOCK_KEY_USMS_MOBILE = "adam:lk:sms:mobile:";
public static final String LOCK_KEY_SMS_CODE_MOBILE = "adam:lk:sms:code:mobile:";
public static final String LOCK_KEY_UREGISTER = "adam:lk:register:";
public static final String LOCK_KEY_UIDENTITY = "adam:lk:identity:";
public static final String LOCK_KEY_UMEMBER_CODE = "adam:lk:member:code:";
......
......@@ -34,7 +34,7 @@ public class DragonConstant {
public enum DeviceFromEnum{
WEB("web",""),WAP("wap","")
,APP("app",""),JS("js",""),APPLE("apple","");
,APP("app",""),JS("js",""),APPLET("applet","");
private String code;
private String message;
DeviceFromEnum(String code, String message) {
......
......@@ -17,6 +17,9 @@ import java.math.BigDecimal;
*/
@Data
public class DragonPayBaseReqDto {
private String payType;
private String deviceFrom;
private String openId;
private String type;
private BigDecimal price;
private String name;
......
......@@ -30,7 +30,7 @@ public class DragonPayBaseRespDto {
private BigDecimal price;
private PayData pay_data;
private PayData payData;
public static class PayData{
@JsonProperty("appId")
......
......@@ -10,5 +10,5 @@ import java.math.BigDecimal;
public interface IDragonOrdersService {
void sendRedisQueue();
ResponseDto<DragonPayBaseRespDto> alipay(DragonPayBaseReqDto dragonPayBaseReqDto);
ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto);
}
......@@ -4,8 +4,22 @@ public class MQConst {
// public static final String EXCHANGES_LIQUIDNET_SQL = "liquidnet.sql";
// public static final String ROUTING_KEY_SQL = "sql";
// public static final String QUEUES_SQL_MAIN = "queue.sql.main";
/* -------------------------------------------------------- | 短信中心 */
/* -------------------------------------------------------- */
// 短信发送
public static final String EX_LNS_SMS_SENDER = "lns.sms.sender";
// 验证码
public static final String RK_SMS_CODE = "sms.code";
public static final String QUEUES_SMS_CODE = "queue.sms.code";
// 通知
public static final String RK_SMS_NOTICE = "sms.notice";
public static final String QUEUES_SMS_NOTICE = "queue.sms.notice";
// 推广(Batch)
public static final String RK_SMS_SPREAD = "sms.spread";
public static final String QUEUES_SMS_SPREAD = "queue.sms.spread";
/* -------------------------------------------------------- | 用户中心 */
// 用户中心
public static final String EX_LNS_SQL_UCENTER = "lns.sql.ucenter";
......@@ -19,7 +33,7 @@ public class MQConst {
public static final String RK_SQL_UMEMBER = "sql.umember";
public static final String QUEUES_SQL_UMEMBER = "queue.sql.umember";
/* -------------------------------------------------------- */
/* -------------------------------------------------------- | 票务中心 */
//缺票登记
public static final String EXCHANGES_LIQUIDNET_SQL_PERFORMANCE_LACK = "liquidnet.sql.performance.lack";
......
package com.liquidnet.service.base;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.liquidnet.commons.lang.util.JsonUtils;
import java.io.Serializable;
public class SmsMessage implements Serializable, Cloneable {
private static final long serialVersionUID = 8484332083582497676L;
private String phone;
private String signName;
private String templateCode;
private ObjectNode templateParam;
public String getPhone() {
return phone;
}
public String getSignName() {
return signName;
}
public String getTemplateCode() {
return templateCode;
}
public ObjectNode getTemplateParam() {
return templateParam;
}
private final static SmsMessage instance = new SmsMessage();
public static SmsMessage builder() {
try {
return (SmsMessage) instance.clone();
} catch (CloneNotSupportedException e) {
return new SmsMessage();
}
}
public SmsMessage setPhone(String phone) {
this.phone = phone;
return this;
}
public SmsMessage setSignName(String signName) {
this.signName = signName;
return this;
}
public SmsMessage setTemplateCode(String templateCode) {
this.templateCode = templateCode;
return this;
}
public SmsMessage setTemplateParam(String key, String val) {
if (null == this.templateParam) {
this.templateParam = JsonUtils.OM().createObjectNode();
}
this.templateParam.put(key, val);
return this;
}
}
......@@ -21,5 +21,10 @@
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-base</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.liquidnet.common.sms.constant;
public class SmsEnum {
/**
* AD:AliyunDysms
* 短信签名
*/
public enum ADSignName {
摩登天空,正在现场,新血计划,摩登小家伙,五百里Live;
}
/**
* AD:AliyunDysms
* 短信模版
*/
public enum ADTemplate {
/**
* 验证码:验证码
* - 您的验证码是:${code}。该验证码15分钟内有效,请不要把验证码泄露给其他人。
* - "{\"code\":\"?1\"}"
*/
SMS_109535335,
/**
* 短信通知:票务 - 用户购票成功后短信通知
* - 尊敬的${userName},您已成功购买${aName},演出时间${time},地点${siteName},此短信不作为入场凭证。您可以登录“正在现场”app查询您的订单及入场方式。也可点此http://ticket.zhengzai.tv${url}
*/
SMS_107075073,
;
}
}
package com.liquidnet.common.sms.processor;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.liquidnet.commons.lang.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Slf4j
@Component
public class SmsProcessor {
/* ================================================================== | aliyun dysms */
@Value("${liquidnet.aliyun.dysms.accessKeyId}")
private String aliyunDysmsAccessKeyId;
@Value("${liquidnet.aliyun.dysms.accessKeySecret}")
private String aliyunDysmsAccessKeySecret;
private static Client aliyunDysmsAcsClient;
/* ================================================================== | */
@PostConstruct
private void init() throws Exception {
Config config = new Config()
.setAccessKeyId(aliyunDysmsAccessKeyId)
.setAccessKeySecret(aliyunDysmsAccessKeySecret)
.setEndpoint("dysmsapi.aliyuncs.com");
aliyunDysmsAcsClient = new Client(config);
}
/**
* AliyunDysms.send
* - link: https://help.aliyun.com/document_detail/101414.htm?spm=a2c4g.11186623.2.8.302f56958lnARh#t83759.html
*
* @param phoneNumber 接收短信的手机号码(国内短信:+/+86/0086/86或无任何前缀的11位手机号码;国际/港澳台消息:国际区号+号码)
* @param signName 短信签名名称
* @param templateCode 短信模板ID
* @param templateParam 短信模板变量对应的实际值,JSON格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createObjectNode())
* @return boolean
*/
public boolean aliyunDysmsSend(String phoneNumber, String signName, String templateCode, String templateParam) {
SendSmsRequest smsRequest = new SendSmsRequest()
.setPhoneNumbers(phoneNumber)
.setSignName(signName)
.setTemplateCode(templateCode)
.setTemplateParam(templateParam);
try {
SendSmsResponse smsResponse = aliyunDysmsAcsClient.sendSms(smsRequest);
SendSmsResponseBody smsResponseBody = smsResponse.getBody();
return null != smsResponseBody && smsResponseBody.getCode().equalsIgnoreCase("OK");
} catch (Exception e) {
log.error("API处理异常", e);
}
return false;
}
/**
* AliyunDysms.sendBatch
* - note: 在一次请求中,最多可以向100个手机号码分别发送短信(整体请求量限定在128k以内)
* - link: https://help.aliyun.com/document_detail/102364.html?spm=a2c4g.11186623.6.633.3d855ecb5j4CR8
*
* @param phoneNumberJson 接收短信的手机号码(国内短信:+/+86/0086/86或无任何前缀的11位手机号码;国际/港澳台消息:国际区号+号码),JSON数组格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createArrayNode())
* @param signNameJson 短信签名名称,JSON数组格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createArrayNode())
* @param templateCode 短信模板CODE
* @param templateParamJson 短信模板变量对应的实际值,JSON格式(建议使用com.liquidnet.commons.lang.util.JsonUtils.OM().createObjectNode())
* @return boolean
*/
public boolean aliyunDysmsSendBatch(String phoneNumberJson, String signNameJson, String templateCode, String templateParamJson) {
SendBatchSmsRequest batchSmsRequest = new SendBatchSmsRequest()
.setPhoneNumberJson(phoneNumberJson)
.setSignNameJson(signNameJson)
.setTemplateCode(templateCode)
.setTemplateParamJson(templateParamJson);
try {
SendBatchSmsResponse batchSmsResponse = aliyunDysmsAcsClient.sendBatchSms(batchSmsRequest);
log.info(JsonUtils.toJson(batchSmsResponse));
SendBatchSmsResponseBody batchSmsResponseBody = batchSmsResponse.getBody();
return null != batchSmsResponseBody && batchSmsResponseBody.getCode().equalsIgnoreCase("OK");
} catch (Exception e) {
log.error("API处理异常", e);
}
return false;
}
}
......@@ -160,6 +160,7 @@
<version>1.1.3</version>
</dependency>
<!-- 短信SDK -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
......
......@@ -80,4 +80,13 @@ liquidnet:
sk: 21e9a70f677a2bf29dfa2b3bead4f018
appid: 557104628450889728
custid: 7551234567
aliyun:
dypns:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessKeySecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
#application-dev-end
\ No newline at end of file
......@@ -30,12 +30,8 @@ liquidnet:
disable: false
redis:
host: r-2ze7002ckw5u75fgukpd.redis.rds.aliyuncs.com
# host: r-2zefzyjbij5vbez65y.redis.rds.aliyuncs.com
port: 6380
password: PO@B!Iud32
# host: r-2ze7002ckw5u75fguk.redis.rds.aliyuncs.com
# port: 6380
# password: PO@B!Iud32
mongodb:
host: s-2zef656730e5a1d4-pub.mongodb.rds.aliyuncs.com:3717,s-2ze49872ed6aeb14-pub.mongodb.rds.aliyuncs.com:3717
port: 3717
......@@ -84,3 +80,13 @@ liquidnet:
sk: 21e9a70f677a2bf29dfa2b3bead4f018
appid: 557104628450889728
custid: 7551234567
aliyun:
dypns:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessKeySecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
#application-test-end
\ No newline at end of file
......@@ -26,9 +26,6 @@ liquidnet:
callback: ${liquidnet.service.adam.url-pay.callback}
url-service:
url: ${liquidnet.service.adam.url-service.url}
aliyun:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessSecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
reviewer:
app-login:
mobile: 13724286255
......
......@@ -26,9 +26,6 @@ liquidnet:
callback: ${liquidnet.service.adam.url-pay.callback}
url-service:
url: ${liquidnet.service.adam.url-service.url}
aliyun:
accessKeyId: LTAI4FvoqxJUT5T1ydJSyhUn
accessSecret: WNCgFn9dSjnoDdej2YTvR0v0216WWU
reviewer:
app-login:
mobile: 13724286255
......
......@@ -23,4 +23,13 @@ liquidnet:
sslEnabled: false
database: dev_ln_scene
dragon:
alipay-gataway-url: https://openapi.alipay.com/gateway.do
alipay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/alipay
wepay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/wepay
merchantId: 1551961491
appId: wx3498304dda39c5a1
parentKey: itIuO65O9yKmemOu3S8g1S4orqvCGwXK
......@@ -22,3 +22,13 @@ liquidnet:
mongodb:
sslEnabled: false
database: test_ln_scene
dragon:
alipay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/alipay
wepay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/wepay
merchantId: 1551961491
appId: wx3498304dda39c5a1
parentKey: itIuO65O9yKmemOu3S8g1S4orqvCGwXK
\ No newline at end of file
......@@ -54,6 +54,12 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-sms</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
......
......@@ -8,14 +8,14 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class AliyunDypnsConfigure {
@Value("${liquidnet.aliyun.accessKeyId}")
@Value("${liquidnet.aliyun.dypns.accessKeyId}")
private String accessKeyId;
@Value("${liquidnet.aliyun.accessSecret}")
private String accessSecret;
@Value("${liquidnet.aliyun.dypns.accessKeySecret}")
private String accessKeySecret;
@Bean
public DefaultAcsClient initAcsClient() {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", accessKeyId, accessKeySecret);
return new DefaultAcsClient(profile);
}
}
......@@ -190,7 +190,8 @@ public class AdamUserController {
@RequestParam String code) {
log.debug("mobile:{},code:{}", mobile, code);
if (!this.checkSmsCode(mobile, code)) return ResponseDto.failure(ErrorMapping.get("10004"));
ResponseDto checkSmsCodeDto = this.checkSmsCode(mobile, code);
if (!checkSmsCodeDto.isSuccess()) return checkSmsCodeDto;
return ResponseDto.success(adamUserInfoService.editMobile(CurrentUtil.getCurrentUid(), mobile));
}
......@@ -241,10 +242,6 @@ public class AdamUserController {
public ResponseDto<List<AdamThirdPartInfoVo>> bindTpa(@Valid @RequestBody AdamThirdPartParam parameter) {
log.debug("login by tpa:{}", JsonUtils.toJson(parameter));
if (StringUtils.isBlank(parameter.getOpenId())) {
return ResponseDto.failure(ErrorMapping.get("10009"));
}
String currentUid = CurrentUtil.getCurrentUid();
String existUid = adamRdmService.getUidByPlatformOpenId(parameter.getPlatform(), parameter.getOpenId());
......@@ -307,27 +304,32 @@ public class AdamUserController {
private static final String PHP_API_SMS_CODE_VALID = "/smsValidation";
private boolean checkSmsCode(String mobile, String code) {
private ResponseDto checkSmsCode(String mobile, String code) {
if (Arrays.asList(LnsEnum.ENV.dev.name(), LnsEnum.ENV.test.name()).contains(env.getProperty(CurrentUtil.CK_ENV_ACTIVE))
&& CurrentUtil.GRAY_LOGIN_SMS_CODE.equals(code)) {
return true;
return ResponseDto.success();
}
LinkedMultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("mobile", mobile);
paramsMap.add("code", code);
LinkedMultiValueMap<String, String> headersMap = new LinkedMultiValueMap<>();
headersMap.add("token", null);
try {
String respStr = HttpUtil.get(env.getProperty("liquidnet.url-service.url") + PHP_API_SMS_CODE_VALID, paramsMap, headersMap);
log.debug("###PHP.API.RESP:{}", respStr);
Map respMap = JsonUtils.fromJson(respStr, Map.class);
return StringUtils.equalsIgnoreCase("OK", (String) respMap.get("message"));
} catch (Exception e) {
log.error("验证码验证异常[mobile:{},code:{}]", mobile, code, e);
return false;
// LinkedMultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
// paramsMap.add("mobile", mobile);
// paramsMap.add("code", code);
// LinkedMultiValueMap<String, String> headersMap = new LinkedMultiValueMap<>();
// headersMap.add("token", null);
// try {
// String respStr = HttpUtil.get(env.getProperty("liquidnet.url-service.url") + PHP_API_SMS_CODE_VALID, paramsMap, headersMap);
// log.debug("###PHP.API.RESP:{}", respStr);
//
// Map respMap = JsonUtils.fromJson(respStr, Map.class);
//
// return StringUtils.equalsIgnoreCase("OK", (String) respMap.get("message"));
// } catch (Exception e) {
// log.error("验证码验证异常[mobile:{},code:{}]", mobile, code, e);
// return false;
// }
String smsCodeByMobile = adamRdmService.getSmsCodeByMobile(mobile);
if (null == smsCodeByMobile) {
return ResponseDto.failure(ErrorMapping.get("10003"));
}
return smsCodeByMobile.equals(code) ? ResponseDto.success() : ResponseDto.failure(ErrorMapping.get("10004"));
}
}
......@@ -35,6 +35,16 @@ public class AdamRdmService {
return null == i ? 1 : i;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | <Mobile, SMS CODE> */
public boolean setSmsCodeByMobile(String mobile, String smsCode) {
return redisUtil.set(AdamRedisConst.VALID_SMS_CODE_MOBILE + mobile, smsCode, 15 * 60);
}
public String getSmsCodeByMobile(String mobile) {
return (String) redisUtil.get(AdamRedisConst.VALID_SMS_CODE_MOBILE + mobile);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | <Mobile|OPENID, UID> */
public boolean setUidByMobile(String mobile, String uid) {
......
......@@ -5,8 +5,8 @@
10000=请求频繁,稍后再试
10001=
10002=
10003=验证码发送失败
10002=验证码发送失败
10003=已超时,请重新获取验证码
10004=手机验证码错误
10005=手机号获取失败,请更换登录方式
10006=第三方账号未注册
......
......@@ -31,6 +31,11 @@
<artifactId>liquidnet-common-cache-redisson</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-sms</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
......
package com.liquidnet.service.consumer.adam.service.processor;
import com.liquidnet.common.mq.constant.MQConst;
import com.liquidnet.common.sms.processor.SmsProcessor;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.SmsMessage;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.consumer.adam.service.IBaseDao;
import com.rabbitmq.client.Channel;
......@@ -28,6 +30,8 @@ import java.io.IOException;
public class ConsumerAdamUCenterProcessor {
@Resource
IBaseDao baseDao;
@Resource
SmsProcessor smsProcessor;
// @RabbitListener(bindings = @QueueBinding(
// exchange = @Exchange(MQConst.EXCHANGES_LIQUIDNET_SQL), key = MQConst.ROUTING_KEY_SQL,
......@@ -62,20 +66,42 @@ public class ConsumerAdamUCenterProcessor {
String consumerQueue = properties.getConsumerQueue();
long deliveryTag = properties.getDeliveryTag();
log.info("CONSUMER SQL ==> [consumerQueue:{},deliveryTag:{}]", consumerQueue, deliveryTag);
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 ==> Parameters:{}", JsonUtils.toJson(sqlMessage.getArgs()));
String msgBody = new String(msg.getBody());
log.debug("CONSUMER SQL ==> Preparing:{}", msgBody);
SqlMapping.SqlMessage sqlMessage = JsonUtils.fromJson(msgBody, SqlMapping.SqlMessage.class);
try {
Boolean rstBatchSqls = baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs());
log.debug("CONSUMER SQL result of execution:{}", rstBatchSqls);
if (rstBatchSqls) {
channel.basicAck(deliveryTag, false);
} else {
log.warn("###CONSUMER SQL[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, JsonUtils.toJson(sqlMessage));
log.warn("###CONSUMER SQL[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody);
channel.basicAck(deliveryTag, false);
}
} catch (IOException e) {
log.error("CONSUMER SQL[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, JsonUtils.toJson(sqlMessage), e);
log.error("CONSUMER SQL[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody, e);
}
}
private void consumerSmsSendHandler(Message msg, Channel channel) {
MessageProperties properties = msg.getMessageProperties();
String consumerQueue = properties.getConsumerQueue();
long deliveryTag = properties.getDeliveryTag();
log.info("CONSUMER SMS ==> [consumerQueue:{},deliveryTag:{}]", consumerQueue, deliveryTag);
String msgBody = new String(msg.getBody());
log.debug("CONSUMER SMS ==> Preparing:{}", msgBody);
SmsMessage smsMessage = JsonUtils.fromJson(msgBody, SmsMessage.class);
try {
boolean result = smsProcessor.aliyunDysmsSend(smsMessage.getPhone(), smsMessage.getSignName(), smsMessage.getTemplateCode(), smsMessage.getTemplateParam().toString());
log.debug("CONSUMER SMS result of execution:{}", result);
if (result) {
channel.basicAck(deliveryTag, false);
} else {
log.warn("###CONSUMER SMS[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody);
channel.basicAck(deliveryTag, false);
}
} catch (IOException e) {
log.error("CONSUMER SMS[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody, e);
}
}
......@@ -121,5 +147,34 @@ public class ConsumerAdamUCenterProcessor {
this.consumerSqlDaoHandler(msg, channel);
}
/* ================================================================== | 短信验证码 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_CODE,
value = @Queue(MQConst.QUEUES_SMS_CODE)
),
concurrency = "10"
)
public void consumerSqlForSmsCode(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | 短信通知 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_NOTICE,
value = @Queue(MQConst.QUEUES_SMS_NOTICE)
),
concurrency = "5"
)
public void consumerSqlForSmsNotice(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | */
}
......@@ -35,7 +35,11 @@
<artifactId>alipay-sdk-java</artifactId>
<version>4.15.6.ALL</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.9</version>
</dependency>
</dependencies>
<build>
......
package com.liquidnet.service.dragon.channel.alipay.biz;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.entity.DragonOrders;
import com.liquidnet.service.dragon.utils.MqHandleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayBiz
* @Package com.liquidnet.service.dragon.channel.alipay.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 16:21
*/
@Component
public class AlipayBiz {
@Autowired
private MqHandleUtil mqHandleUtil;
public DragonOrders buildPayOrders(DragonPayBaseReqDto dragonPayBaseReqDto, DragonPayBaseRespDto respDto){
DragonOrders orders = new DragonOrders();
// orders.setMid();
orders.setStatus(Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_UNPAID.getCode()));
orders.setCode(respDto.getCode());
orders.setType(dragonPayBaseReqDto.getType());
orders.setPrice(dragonPayBaseReqDto.getPrice());
orders.setName(dragonPayBaseReqDto.getName());
orders.setDetail(dragonPayBaseReqDto.getDetail());
orders.setOrderCode(dragonPayBaseReqDto.getOrderCode());
orders.setClientIp(dragonPayBaseReqDto.getClientIp());
orders.setNotifyUrl(dragonPayBaseReqDto.getNotifyUrl());
orders.setPaymentType(DragonConstant.PayTypeEnum.PAYMENT_TYPE_APP_IAP.getCode());
// orders.setPaymentId();
orders.setPaymentAt(LocalDateTime.now());
// orders.setFinishedAt();
orders.setCreatedAt(LocalDateTime.now());
// orders.setUpdatedAt();
// 修改退款订单
boolean insertResult = mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_orders.insert"),
new Object[]{orders.getStatus(), orders.getCode(), orders.getType()
, orders.getPrice(), orders.getName(), orders.getDetail()
, orders.getOrderCode(), orders.getClientIp()
, orders.getNotifyUrl(), orders.getPaymentType(),
orders.getPaymentId(), orders.getPaymentAt()
, orders.getFinishedAt(), orders.getCreatedAt()
, orders.getUpdatedAt()}
);
return orders;
}
}
package com.liquidnet.service.dragon.channel.alipay.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy;
import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
......@@ -20,8 +29,36 @@ import org.springframework.stereotype.Component;
@Component
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.APP)
public class AlipayStrategyAppImpl implements IAlipayStrategy {
@Autowired
StringRedisTemplate stringRedisTemplate;
@Value("liquidnet.dragon.alipay.gataway-url")
private String alipayGatewayUrl;
@Autowired
private AlipayBiz alipayBiz;
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
AlipayTradePayReq alipayTradePayReq = new AlipayTradePayReq();
alipayTradePayReq.setProductCode("QUICK_WAP_PAY");
alipayTradePayReq.setTotalAmount(dragonPayBaseReqDto.getPrice());
alipayTradePayReq.setSubject(dragonPayBaseReqDto.getName());
alipayTradePayReq.setBody(dragonPayBaseReqDto.getDetail());
//dragon中支付编号
alipayTradePayReq.setOutTradeNo(IDGenerator.payCode());
alipayTradePayReq.setTimeExpire(dragonPayBaseReqDto.getExpireTime());
//调用支付
Map<String, Object> result = AlipayUtil.tradeWapPay(alipayTradePayReq);
//拼接返回参数
DragonPayBaseRespDto respDto = new DragonPayBaseRespDto();
respDto.setCode(alipayTradePayReq.getOutTradeNo());
respDto.setOrder_code(dragonPayBaseReqDto.getOrderCode());
DragonPayBaseRespDto.PayData payData = new DragonPayBaseRespDto.PayData();
payData.setRedirectUrl(alipayGatewayUrl + result.get("body"));
respDto.setPayData(payData);
//支付订单持久化
alipayBiz.buildPayOrders(dragonPayBaseReqDto,respDto);
return ResponseDto.success(respDto);
}
}
package com.liquidnet.service.dragon.channel.alipay.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy;
import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
......@@ -17,11 +27,39 @@ import org.springframework.stereotype.Component;
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Component
@Service
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.WAP)
public class AlipayStrategyWapImpl implements IAlipayStrategy {
@Autowired
StringRedisTemplate stringRedisTemplate;
@Value("${liquidnet.dragon.alipay.gataway-url}")
private String alipayGatewayUrl;
@Autowired
private AlipayBiz alipayBiz;
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
AlipayTradePayReq alipayTradePayReq = new AlipayTradePayReq();
alipayTradePayReq.setProductCode("QUICK_WAP_PAY");
alipayTradePayReq.setTotalAmount(dragonPayBaseReqDto.getPrice());
alipayTradePayReq.setSubject(dragonPayBaseReqDto.getName());
alipayTradePayReq.setBody(dragonPayBaseReqDto.getDetail());
//dragon中支付编号
alipayTradePayReq.setOutTradeNo(IDGenerator.payCode());
alipayTradePayReq.setTimeExpire(dragonPayBaseReqDto.getExpireTime());
//调用支付
Map<String, Object> result = AlipayUtil.tradeWapPay(alipayTradePayReq);
//拼接返回参数
DragonPayBaseRespDto respDto = new DragonPayBaseRespDto();
respDto.setCode(alipayTradePayReq.getOutTradeNo());
respDto.setOrder_code(dragonPayBaseReqDto.getOrderCode());
DragonPayBaseRespDto.PayData payData = new DragonPayBaseRespDto.PayData();
payData.setRedirectUrl(alipayGatewayUrl + "?" + result.get("body"));
respDto.setPayData(payData);
//支付订单持久化
alipayBiz.buildPayOrders(dragonPayBaseReqDto,respDto);
return ResponseDto.success(respDto);
}
}
package com.liquidnet.service.dragon.channel.alipay.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy;
import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
......@@ -20,9 +29,36 @@ import org.springframework.stereotype.Component;
@Component
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.WEB)
public class AlipayStrategyWebImpl implements IAlipayStrategy {
@Autowired
StringRedisTemplate stringRedisTemplate;
@Value("liquidnet.dragon.alipay.gataway-url")
private String alipayGatewayUrl;
@Autowired
private AlipayBiz alipayBiz;
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
AlipayTradePayReq alipayTradePayReq = new AlipayTradePayReq();
alipayTradePayReq.setProductCode("QUICK_WAP_PAY");
alipayTradePayReq.setTotalAmount(dragonPayBaseReqDto.getPrice());
alipayTradePayReq.setSubject(dragonPayBaseReqDto.getName());
alipayTradePayReq.setBody(dragonPayBaseReqDto.getDetail());
//dragon中支付编号
alipayTradePayReq.setOutTradeNo(IDGenerator.payCode());
alipayTradePayReq.setTimeExpire(dragonPayBaseReqDto.getExpireTime());
//调用支付
Map<String, Object> result = AlipayUtil.tradeWapPay(alipayTradePayReq);
//拼接返回参数
DragonPayBaseRespDto respDto = new DragonPayBaseRespDto();
respDto.setCode(alipayTradePayReq.getOutTradeNo());
respDto.setOrder_code(dragonPayBaseReqDto.getOrderCode());
DragonPayBaseRespDto.PayData payData = new DragonPayBaseRespDto.PayData();
payData.setRedirectUrl(alipayGatewayUrl + result.get("body"));
respDto.setPayData(payData);
//支付订单持久化
alipayBiz.buildPayOrders(dragonPayBaseReqDto,respDto);
return ResponseDto.success(respDto);
}
}
......@@ -44,46 +44,6 @@ public class AlipayUtil {
}
/**
* 支付宝支付
* @param alipayTradePayReq
* @return
*/
public static Map<String, Object> tradePagePay(AlipayTradePayReq alipayTradePayReq) {
logger.info("AlipayUtil.tradePay-->> req : {}",alipayTradePayReq.toString());
String timeExpress = "5m";// 支付超时,线下扫码交易定义为5分钟
AlipayClient alipayClient = PayAlipayUtils.getHttpClient();
SortedMap<String, Object> paramMap = new TreeMap<>();
paramMap.put("product_code", alipayTradePayReq.getProductCode());
paramMap.put("total_amount", alipayTradePayReq.getTotalAmount().toString());
paramMap.put("subject", alipayTradePayReq.getSubject());
paramMap.put("body", alipayTradePayReq.getBody());
paramMap.put("out_trade_no", alipayTradePayReq.getOutTradeNo());
paramMap.put("timeout_express", timeExpress);
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
request.setNotifyUrl("https://testpay.zhengzai.tv");
// request.setTimestamp(DateUtil.now());
logger.info("bizContent :{}",JSONObject.toJSONString(paramMap));
request.setBizContent(JSONObject.toJSONString(paramMap));
try {
AlipayTradePagePayResponse response = alipayClient.sdkExecute(request);
JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
logger.info("支付宝返回结果:{}", responseJSON);
return responseJSON;
} catch (AlipayApiException e) {
logger.error("支付宝支付异常:{}", e);
JSONObject resultJSON = new JSONObject();
resultJSON.put("outTradeNo", alipayTradePayReq.getOutTradeNo());
resultJSON.put("totalAmount", alipayTradePayReq.getTotalAmount().toString());
resultJSON.put("errorCode", "9999");
return resultJSON;
}
}
/**
* 支付宝支付
* @param alipayTradePayReq
......@@ -93,7 +53,7 @@ public class AlipayUtil {
logger.info("AlipayUtil.tradePay-->> req : {}",alipayTradePayReq.toString());
String timeExpress = "5m";// 支付超时,线下扫码交易定义为5分钟
AlipayClient alipayClient = PayAlipayUtils.getHttpClient();
AlipayClient alipayClient = PayAlipayUtils.getInstance().getHttpClient();
SortedMap<String, Object> paramMap = new TreeMap<>();
paramMap.put("product_code", alipayTradePayReq.getProductCode());
......@@ -127,6 +87,7 @@ public class AlipayUtil {
}
}
/**
* 订单查询
*
......
package com.liquidnet.service.dragon.channel.strategy.impl;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext;
import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy;
import com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
......@@ -23,9 +22,11 @@ import java.util.List;
@Component
@StrategyPayChannelHandler(DragonConstant.PayChannelEnum.ALIPAY)
public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy {
@Autowired
private AlipayStrategyContext alipayStrategyContext;
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
return alipayStrategyContext.getStrategy(dragonPayBaseReqDto.getDeviceFrom()).dragonPay(dragonPayBaseReqDto);
}
}
package com.liquidnet.service.dragon.channel.strategy.impl;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext;
import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy;
import com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler;
import com.liquidnet.service.dragon.channel.wepay.strategy.WepayStrategyContext;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
......@@ -23,9 +26,11 @@ import java.util.List;
@Component
@StrategyPayChannelHandler(DragonConstant.PayChannelEnum.WEPAY)
public class PayChannelStrategyWepayImpl implements IPayChannelStrategy {
@Autowired
private WepayStrategyContext wepayStrategyContext;
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
return wepayStrategyContext.getStrategy(dragonPayBaseReqDto.getDeviceFrom()).dragonPay(dragonPayBaseReqDto);
}
}
package com.liquidnet.service.dragon.channel.wepay.biz;
import com.liquidnet.service.dragon.channel.wepay.req.WepayPrePayReq;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: WepayBiz
* @Package com.liquidnet.service.dragon.channel.wepay.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 16:46
*/
@Slf4j
@Component
public class WepayBiz {
public WepayPrePayReq sealWeixinPerPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
WepayPrePayReq WepayPrePayReq = new WepayPrePayReq();
// WepayPrePayReq.setAppid(appId);
// WepayPrePayReq.setMchId(mchId);
// WepayPrePayReq.setBody(productName);// 商品描述
// WepayPrePayReq.setAttach(remark);// 支付备注
// WepayPrePayReq.setOutTradeNo(bankOrderNo);// 银行订单号
//
// Integer totalFee = orderPrice.multiply(BigDecimal.valueOf(100d)).intValue();
// WepayPrePayReq.setTotalFee(totalFee);// 订单金额
// WepayPrePayReq.setTimeStart(DateUtil.parse(orderTime, "yyyyMMddHHmmss"));// 订单开始时间
//// WepayPrePayReq.setTimeExpire(DateUtil.formatDate(DateUtil.addMinute(orderTime, orderPeriod), "yyyyMMddHHmmss"));// 订单到期时间
// WepayPrePayReq.setNotifyUrl(WeixinConfigUtil.readConfig("notify_url"));// 通知地址
//// WepayPrePayReq.setTradeType("");// 交易类型
// WepayPrePayReq.setProductId(productId);// 商品ID
// WepayPrePayReq.setOpenid(openId);// 用户标识
// WepayPrePayReq.setSpbillCreateIp(orderIp);// 下单IP
return WepayPrePayReq;
}
}
/*
* Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.liquidnet.service.dragon.channel.wepay.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.util.Properties;
/**
* <b>功能说明:微信属性文件工具类
* </b>
* @author Peter
* <a href="http://www.roncoo.com">龙果学院(www.roncoo.com)</a>
*/
public class WeixinConfigUtil {
private static final Log LOG = LogFactory.getLog(WeixinConfigUtil.class);
/**
* 通过静态代码块读取上传文件的验证格式配置文件,静态代码块只执行一次(单例)
*/
private static Properties properties = new Properties();
private WeixinConfigUtil() {
}
// 通过类装载器装载进来
static {
try {
// 从类路径下读取属性文件
properties.load(WeixinConfigUtil.class.getClassLoader()
.getResourceAsStream("weixinpay_config.properties"));
} catch (IOException e) {
LOG.error(e);
}
}
/**
* 函数功能说明 :读取配置项 Administrator 2012-12-14 修改者名字 : 修改日期 : 修改内容 :
*
* @参数:
* @return void
* @throws
*/
public static String readConfig(String key) {
return (String) properties.get(key);
}
//app_id
public static final String appId = (String) properties.get("appId");
//商户号
public static final String mch_id = (String) properties.get("mch_id");
//商户秘钥
public static final String partnerKey = (String) properties.get("partnerKey");
//小程序支付
public static final String xAuthUrl = (String) properties.get("x_auth_url");
public static final String xGrantType = (String) properties.get("x_grant_type");
public static final String xAppId = (String) properties.get("x_appId");
public static final String xPartnerKey = (String) properties.get("x_partnerKey");
public static final String xPayKey = (String) properties.get("x_payKey");
public static final String xMchId = (String) properties.get("x_mch_id");
public static final String x_notify_url = (String) properties.get("x_notify_url");
}
/*
* Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.liquidnet.service.dragon.channel.wepay.req;
import com.liquidnet.commons.lang.util.IDGenerator;
import java.io.Serializable;
/**
* <b>功能说明:微信预支付实体类</b>
* @author Peter
* <a href="http://www.roncoo.com">龙果学院(www.roncoo.com)</a>
*/
public class WepayPrePayReq implements Serializable {
/** 公众账号ID 必填 **/
private String appid;
/** 商户号 必填 **/
private String mchId;
/** 设备号 终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB" 默认为'WEB'**/
private String deviceInfo = "WEB";
/** 随机字符串 **/
private String nonceStr = IDGenerator.get32UUID();
/** 签名 **/
private String sign;
/** 商品描述 **/
private String body;
/** 商品详情 **/
private String detail;
/** 附加数据 **/
private String attach;
/** 商户订单号 **/
private String outTradeNo;
/** 货币类型 默认为人民币 **/
private String feeType = "CNY";
/** 总金额 **/
private Integer totalFee;
/** 终端IP **/
private String spbillCreateIp;
/** 交易起始时间 **/
private String timeStart;
/** 交易结束时间 **/
private String timeExpire;
/** 商品标记 **/
private String goodsTag;
/** 通知地址 **/
private String notifyUrl;
/** 商品ID **/
private String productId;
/** 制定支付方式 **/
private String limitPay;
/** 用户标识 **/
private String openid;
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public String getAttach() {
return attach;
}
public void setAttach(String attach) {
this.attach = attach;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getMchId() {
return mchId;
}
public void setMchId(String mchId) {
this.mchId = mchId;
}
public String getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(String deviceInfo) {
this.deviceInfo = deviceInfo;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
public String getOutTradeNo() {
return outTradeNo;
}
public void setOutTradeNo(String outTradeNo) {
this.outTradeNo = outTradeNo;
}
public String getFeeType() {
return feeType;
}
public void setFeeType(String feeType) {
this.feeType = feeType;
}
public Integer getTotalFee() {
return totalFee;
}
public void setTotalFee(Integer totalFee) {
this.totalFee = totalFee;
}
public String getSpbillCreateIp() {
return spbillCreateIp;
}
public void setSpbillCreateIp(String spbillCreateIp) {
this.spbillCreateIp = spbillCreateIp;
}
public String getTimeStart() {
return timeStart;
}
public void setTimeStart(String timeStart) {
this.timeStart = timeStart;
}
public String getTimeExpire() {
return timeExpire;
}
public void setTimeExpire(String timeExpire) {
this.timeExpire = timeExpire;
}
public String getGoodsTag() {
return goodsTag;
}
public void setGoodsTag(String goodsTag) {
this.goodsTag = goodsTag;
}
public String getNotifyUrl() {
return notifyUrl;
}
public void setNotifyUrl(String notifyUrl) {
this.notifyUrl = notifyUrl;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getLimitPay() {
return limitPay;
}
public void setLimitPay(String limitPay) {
this.limitPay = limitPay;
}
}
package com.liquidnet.service.dragon.channel.wepay.resp;
import com.liquidnet.service.dragon.utils.XmlUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: WepayPayRespDto
* @Package com.liquidnet.service.dragon.channel.wepay.resp
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/12 10:40
*/
@Data
@XStreamAlias("xml")
public class WepayPayRespDto {
@XStreamAlias("return_code")
private String returnCode; //SUCCESS
@XStreamAlias("return_msg")
private String returnMsg; //OK
@XStreamAlias("result_code")
private String resultCode; //SUCCESS
@XStreamAlias("mch_id")
private String mchId; //1551961491
@XStreamAlias("appid")
private String appid; //wx3498304dda39c5a1
@XStreamAlias("nonce_str")
private String nonceStr; //Y6Czfx4lhuSv0yUD
@XStreamAlias("sign")
private String sign; //97001E77813055D03E3009F67A836D62
@XStreamAlias("prepay_id")
private String prepayId; //wx111130490949693ab00f679072ea730000
@XStreamAlias("trade_type")
private String tradeType; //MWEB
@XStreamAlias("mweb_url")
private String mwebUrl; //https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx111130490949693ab00f679072ea730000&package=2011082926
public static void xmlToBean(){
String xmlStr = "<xml><return_code><![CDATA[SUCCESS]]></return_code>\n" +
"<return_msg><![CDATA[OK]]></return_msg>\n" +
"<result_code><![CDATA[SUCCESS]]></result_code>\n" +
"<mch_id><![CDATA[1551961491]]></mch_id>\n" +
"<appid><![CDATA[wx3498304dda39c5a1]]></appid>\n" +
"<nonce_str><![CDATA[Y6Czfx4lhuSv0yUD]]></nonce_str>\n" +
"<sign><![CDATA[97001E77813055D03E3009F67A836D62]]></sign>\n" +
"<prepay_id><![CDATA[wx111130490949693ab00f679072ea730000]]></prepay_id>\n" +
"<trade_type><![CDATA[MWEB]]></trade_type>\n" +
"<mweb_url><![CDATA[https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx111130490949693ab00f679072ea730000&package=2011082926]]></mweb_url>\n" +
"</xml> ";
WepayPayRespDto respDto= XmlUtil.toBean(xmlStr, WepayPayRespDto.class);
System.out.println("respDto.getAppid()=="+respDto.getAppid());
System.out.println("respDto.getMwebUrl()==="+respDto.getMwebUrl());
}
public static void main(String[] args) {
xmlToBean();
}
}
package com.liquidnet.service.dragon.channel.wepay.strategy;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: Test
* @Package com.liquidnet.service.dragon.channel.strategy
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:27
*/
public interface IWepayStrategy {
ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto);
}
package com.liquidnet.service.dragon.channel.wepay.strategy;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: Test
* @Package com.liquidnet.service.dragon.channel.strategy
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:27
*/
@Component
public class WepayStrategyContext {
private final Map<String, IWepayStrategy> handlerMap = new HashMap<>();
public IWepayStrategy getStrategy(String type) {
return handlerMap.get(type);
}
public void putStrategy(String code, IWepayStrategy strategy) {
handlerMap.put(code, strategy);
}
}
package com.liquidnet.service.dragon.channel.wepay.strategy;
import com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: Test
* @Package com.liquidnet.service.dragon.channel.strategy
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:27
*/
@Component
public class WepayStrategyListener implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
Map<String, Object> beans = event.getApplicationContext().getBeansWithAnnotation(StrategyWepayHandler.class);
WepayStrategyContext strategyContext = event.getApplicationContext().getBean(WepayStrategyContext.class);
beans.forEach((name, bean) -> {
StrategyWepayHandler typeHandler = bean.getClass().getAnnotation(StrategyWepayHandler.class);
strategyContext.putStrategy(typeHandler.value().getCode(), (IWepayStrategy) bean);
});
}
}
\ No newline at end of file
package com.liquidnet.service.dragon.channel.wepay.strategy.annotation;
import com.liquidnet.service.dragon.constant.DragonConstant;
import java.lang.annotation.*;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
* @Description: TODO
* @class: StrategyGetFundDataHandler
* @Package com.liquidnet.service.reconciliation.strategy.annotation
* @Copyright: LightNet @ Copyright (c) 2020
* @date 2020/10/27 15:29
*/
@Documented
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface StrategyWepayHandler {
DragonConstant.DeviceFromEnum value();
}
package com.liquidnet.service.dragon.channel.wepay.strategy.impl;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.wepay.strategy.IWepayStrategy;
import com.liquidnet.service.dragon.channel.wepay.util.WepayUtil;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.utils.PayWepayUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import java.util.SortedMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AbstractWepayStrategy
* @Package com.liquidnet.service.dragon.channel.wepay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/11 11:56
*/
@Slf4j
public abstract class AbstractWepayStrategy implements IWepayStrategy {
@Value("${liquidnet.dragon.wepay.parentKey}")
private String parentKey;
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
try {
//构造请求参数
SortedMap<String, Object> parameters = this.buildRequestParamMap(dragonPayBaseReqDto);
//生成签名
String sign = WepayUtil.getSign(parameters,parentKey);
parameters.put("sign", sign);
//构造支付请求xml
String data = WepayUtil.mapToXml(parameters);
HttpPost httpost = new HttpPost(this.getRequestUrl());
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = PayWepayUtils.getInstance().getHttpClient().execute(httpost);
HttpEntity entity = response.getEntity();
//接受到返回信息
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
log.info("dragonPay:wepay:wap response json: {} ",jsonStr);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 构造请求参数
* @return
*/
abstract SortedMap<String, Object> buildRequestParamMap(DragonPayBaseReqDto dragonPayBaseReqDto);
/**
* 构造返回参数
*/
abstract DragonPayBaseRespDto buildResponseDto();
protected abstract String getRequestUrl();
}
package com.liquidnet.service.dragon.channel.wepay.strategy.impl;
import com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.SortedMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayStrategyWapImpl
* @Package com.liquidnet.service.dragon.channel.alipay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Slf4j
@Component
@StrategyWepayHandler(DragonConstant.DeviceFromEnum.APP)
public class WepayStrategyAppImpl extends AbstractWepayStrategy {
@Override
SortedMap<String, Object> buildRequestParamMap(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
}
@Override
DragonPayBaseRespDto buildResponseDto() {
return null;
}
@Override
protected String getRequestUrl() {
return null;
}
}
package com.liquidnet.service.dragon.channel.wepay.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.utils.PayWepayUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayStrategyWapImpl
* @Package com.liquidnet.service.dragon.channel.alipay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Slf4j
@Component
@StrategyWepayHandler(DragonConstant.DeviceFromEnum.APPLET)
public class WepayStrategyAppletImpl extends AbstractWepayStrategy{
@Override
SortedMap<String, Object> buildRequestParamMap(DragonPayBaseReqDto dragonPayBaseReqDto) {
String nonceStr = PayWepayUtils.getInstance().getNonceStr();
SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantId());
parameters.put("appid", PayWepayUtils.getInstance().getAppId());
parameters.put("nonce_str", nonceStr);
parameters.put("spbill_create_ip", dragonPayBaseReqDto.getClientIp());
parameters.put("total_fee", dragonPayBaseReqDto.getPrice().multiply(BigDecimal.valueOf(100L)).intValue());
parameters.put("body", dragonPayBaseReqDto.getName());
parameters.put("detail", dragonPayBaseReqDto.getDetail());
parameters.put("out_trade_no", IDGenerator.payCode());
parameters.put("time_expire", "20210908103456");
parameters.put("notify_url", "https://www.baidu.com");
parameters.put("trade_type", "MWEB");
return parameters;
}
@Override
DragonPayBaseRespDto buildResponseDto() {
return null;
}
@Override
protected String getRequestUrl() {
return "https://api.mch.weixin.qq.com/pay/unifiedorder";
}
}
package com.liquidnet.service.dragon.channel.wepay.strategy.impl;
import com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.SortedMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayStrategyWapImpl
* @Package com.liquidnet.service.dragon.channel.alipay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Slf4j
@Component
@StrategyWepayHandler(DragonConstant.DeviceFromEnum.JS)
public class WepayStrategyJsImpl extends AbstractWepayStrategy{
@Override
SortedMap<String, Object> buildRequestParamMap(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
}
@Override
DragonPayBaseRespDto buildResponseDto() {
return null;
}
@Override
protected String getRequestUrl() {
return null;
}
}
package com.liquidnet.service.dragon.channel.wepay.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.utils.PayWepayUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayStrategyWapImpl
* @Package com.liquidnet.service.dragon.channel.alipay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Slf4j
@Component
@StrategyWepayHandler(DragonConstant.DeviceFromEnum.WAP)
public class WepayStrategyWapImpl extends AbstractWepayStrategy{
@Override
SortedMap<String, Object> buildRequestParamMap(DragonPayBaseReqDto dragonPayBaseReqDto) {
String nonceStr = PayWepayUtils.getInstance().getNonceStr();
SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantId());
parameters.put("appid", PayWepayUtils.getInstance().getAppId());
parameters.put("nonce_str", nonceStr);
parameters.put("spbill_create_ip", dragonPayBaseReqDto.getClientIp());
parameters.put("total_fee", dragonPayBaseReqDto.getPrice().multiply(BigDecimal.valueOf(100L)).intValue());
parameters.put("body", dragonPayBaseReqDto.getName());
parameters.put("detail", dragonPayBaseReqDto.getDetail());
parameters.put("out_trade_no", IDGenerator.payCode());
parameters.put("time_expire", "20210908103456");
parameters.put("notify_url", "https://www.baidu.com");
parameters.put("trade_type", "MWEB");
return parameters;
}
@Override
DragonPayBaseRespDto buildResponseDto() {
return null;
}
@Override
protected String getRequestUrl() {
return "https://api.mch.weixin.qq.com/pay/unifiedorder";
}
}
/*
* Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.liquidnet.service.dragon.channel.wepay.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.security.MessageDigest;
/**
* <b>功能说明:MD5签名工具类
* </b>
* @author Peter
* <a href="http://www.roncoo.com">龙果学院(www.roncoo.com)</a>
*/
public class MD5Util {
private static final Logger LOG = LoggerFactory.getLogger(MD5Util.class);
/**
* 私有构造方法,将该工具类设为单例模式.
*/
private MD5Util() {
}
private static final String[] hex = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
public static String encode(String password) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] byteArray = md5.digest(password.getBytes("utf-8"));
String passwordMD5 = byteArrayToHexString(byteArray);
return passwordMD5;
} catch (Exception e) {
LOG.error(e.toString());
}
return password;
}
private static String byteArrayToHexString(byte[] byteArray) {
StringBuffer sb = new StringBuffer();
for (byte b : byteArray) {
sb.append(byteToHexChar(b));
}
return sb.toString();
}
private static Object byteToHexChar(byte b) {
int n = b;
if (n < 0) {
n = 256 + n;
}
int d1 = n / 16;
int d2 = n % 16;
return hex[d1] + hex[d2];
}
}
......@@ -36,8 +36,8 @@ public class PayController {
* 电脑网页支付宝支付
* @return
*/
@PostMapping("/web/alipay")
@ApiOperation("支付宝web支付")
@PostMapping("/dragonPay")
@ApiOperation("Dragon支付")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "payType", value = "支付类型:alipay,wepay,iappay", example = "alipay"),
......@@ -50,9 +50,10 @@ public class PayController {
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "clientIp", value = "客户端ip", example = "127.0.0.1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "notifyUrl", value = "通知url", example = "pay.zhengzai.tv"),
})
public ResponseDto<DragonPayBaseRespDto> webAlipay(
@RequestParam(value = "payType") @NotNull(message = "支付类型不能为空") BigDecimal payType,
@RequestParam(value = "deviceFrom") @NotNull(message = "设备来源不能为空") BigDecimal deviceFrom,
public ResponseDto<DragonPayBaseRespDto> dragonPay(
@RequestParam(value = "payType") @NotNull(message = "支付类型不能为空") String payType,
@RequestParam(value = "deviceFrom") @NotNull(message = "设备来源不能为空") String deviceFrom,
@RequestParam(value = "openId") @NotNull(message = "微信支付openId不能为空") String openId,
@RequestParam(value = "type") @NotNull(message = "业务类型不能为空") String type,
@RequestParam(value = "price") @NotNull(message = "支付金额不能为空") BigDecimal price,
@RequestParam(value = "name") @NotNull(message = "订单名称不能为空") String name,
......@@ -67,6 +68,9 @@ public class PayController {
@RequestParam(value = "createDate",required = false) String createDate,
@RequestParam(value = "expireTime",required = false) String expireTime){
DragonPayBaseReqDto dragonPayBaseReqDto = new DragonPayBaseReqDto();
dragonPayBaseReqDto.setPayType(payType);
dragonPayBaseReqDto.setDeviceFrom(deviceFrom);
dragonPayBaseReqDto.setOpenId(openId);
dragonPayBaseReqDto.setType(type);
dragonPayBaseReqDto.setPrice(price);
dragonPayBaseReqDto.setName(name);
......@@ -74,126 +78,6 @@ public class PayController {
dragonPayBaseReqDto.setOrderCode(orderCode);
dragonPayBaseReqDto.setClientIp(clientIp);
dragonPayBaseReqDto.setNotifyUrl(notifyUrl);
return dragonOrdersService.alipay(dragonPayBaseReqDto);
return dragonOrdersService.dragonPay(dragonPayBaseReqDto);
}
/**
* 手机网页支付宝支付
* @return
*/
@PostMapping("/wap/alipay")
@ApiOperation("支付宝wap支付")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "type", value = "支付类型:TICKET,PRODUCT,COST,MBEANS,LIVE,VIDEO,VIP,CLUB,STRAWBERRY", example = "TICKET"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "price", value = "支付金额", example = "0.1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "name", value = "订单名称", example = "测试订单001"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "detail", value = "订单描述", example = "测试订单001"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderCode", value = "订单编号", example = "ORDER0001"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "clientIp", value = "客户端ip", example = "127.0.0.1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "notifyUrl", value = "通知url", example = "pay.zhengzai.tv"),
})
public ResponseDto<DragonPayBaseRespDto> wapAlipay(@RequestParam(value = "type") @NotNull(message = "支付类型不能为空") String type,
@RequestParam(value = "price") @NotNull(message = "支付金额不能为空") BigDecimal price,
@RequestParam(value = "name") @NotNull(message = "订单名称不能为空") String name,
@RequestParam(value = "detail") @NotNull(message = "订单描述不能为空") String detail,
@RequestParam(value = "orderCode") @NotNull(message = "订单编号不能为空") String orderCode,
@RequestParam(value = "clientIp") @NotNull(message = "客户端ip不能为空") String clientIp,
@RequestParam(value = "notifyUrl") @NotNull(message = "通知Url不能为空") String notifyUrl,
@RequestParam(value = "returnUrl",required = false) String returnUrl,
@RequestParam(value = "quitUrl",required = false) String quitUrl,
@RequestParam(value = "showUrl",required = false) String showUrl,
@RequestParam(value = "code",required = false) String code,
@RequestParam(value = "createDate",required = false) String createDate,
@RequestParam(value = "expireTime",required = false) String expireTime){
DragonPayBaseReqDto dragonPayBaseReqDto = new DragonPayBaseReqDto();
dragonPayBaseReqDto.setType(type);
dragonPayBaseReqDto.setPrice(price);
dragonPayBaseReqDto.setName(name);
dragonPayBaseReqDto.setDetail(detail);
dragonPayBaseReqDto.setOrderCode(orderCode);
dragonPayBaseReqDto.setClientIp(clientIp);
dragonPayBaseReqDto.setNotifyUrl(notifyUrl);
return dragonOrdersService.alipay(dragonPayBaseReqDto);
}
// /**
// * 电脑网页微信支付
// * @return
// */
// @PostMapping("/web/wepay")
// @ApiOperation("微信web支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto webWepay(){
// return null;
// }
//
//
// /**
// * 手机网页微信支付
// * @return
// */
// @PostMapping("/wap/wepay")
// @ApiOperation("微信wap支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto wapWepay(){
// return null;
// }
//
// /**
// * App内支付宝支付
// * @return
// */
// @PostMapping("/app/alipay")
// @ApiOperation("支付宝app支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto appAlipay(){
// return null;
// }
//
// /**
// * App内微信支付
// * @return
// */
// @PostMapping("/app/wepay")
// @ApiOperation("微信app支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto appWepay(){
// return null;
// }
//
// /**
// * Apple(In-App Purchase) 支付
// * @return
// */
// @PostMapping("/app/iappay")
// @ApiOperation("Apple支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto appIappay(){
// return null;
// }
//
// /**
// * 微信内网页、公众号支付
// * @return
// */
// @PostMapping("/js/wepay")
// @ApiOperation("微信内网页、公众号支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto jsWepay(){
// return null;
// }
//
// /**
// * 微信小程序支付
// * @return
// */
// @PostMapping("/applet/wepay")
// @ApiOperation("微信小程序支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto appletWepay(){
// return null;
// }
}
package com.liquidnet.service.dragon.controller;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: PayNotifyController
* @Package com.liquidnet.service.dragon.controller
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/11 23:35
*/
@RestController
@RequestMapping("pay")
public class PayNotifyController {
/**
* 支付宝支付回调
* @return
*/
@PostMapping("/notify/alipay")
@ApiOperation("支付宝支付回调")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "payType", value = "支付类型:alipay,wepay,iappay", example = "alipay")
})
public ResponseDto<DragonPayBaseRespDto> notifyAlipay(
@RequestParam(value = "payType") @NotNull(message = "支付类型不能为空") String payType){
return null;
}
/**
* 微信支付回调
* @return
*/
@PostMapping("/notify/wepay")
@ApiOperation("支付宝支付回调")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "payType", value = "支付类型:alipay,wepay,iappay", example = "alipay")
})
public ResponseDto<DragonPayBaseRespDto> notifyWepay(
@RequestParam(value = "payType") @NotNull(message = "支付类型不能为空") String payType){
return null;
}
}
package com.liquidnet.service.dragon.service.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.entity.DragonOrders;
import com.liquidnet.service.dragon.service.IDragonOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
@Slf4j
@Service
public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Autowired
StringRedisTemplate stringRedisTemplate;
@Value("liquidnet.dragon.alipay-gataway-url")
private String alipayGatewayUrl;
@Autowired
private PayChannelStrategyContext payChannelStrategyContext;
@Override
public void sendRedisQueue() {
......@@ -42,81 +36,7 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
}
@Override
public ResponseDto<DragonPayBaseRespDto> alipay(DragonPayBaseReqDto dragonPayBaseReqDto) {
AlipayTradePayReq alipayTradePayReq = new AlipayTradePayReq();
alipayTradePayReq.setProductCode("QUICK_WAP_PAY");
alipayTradePayReq.setTotalAmount(dragonPayBaseReqDto.getPrice());
alipayTradePayReq.setSubject(dragonPayBaseReqDto.getName());
alipayTradePayReq.setBody(dragonPayBaseReqDto.getDetail());
//dragon中支付编号
alipayTradePayReq.setOutTradeNo(IDGenerator.payCode());
alipayTradePayReq.setTimeExpire(dragonPayBaseReqDto.getExpireTime());
Map<String, Object> result = AlipayUtil.tradeWapPay(alipayTradePayReq);
DragonPayBaseRespDto respDto = new DragonPayBaseRespDto();
respDto.setCode(alipayTradePayReq.getOutTradeNo());
respDto.setOrder_code(dragonPayBaseReqDto.getOrderCode());
DragonPayBaseRespDto.PayData payData = new DragonPayBaseRespDto.PayData();
payData.setRedirectUrl(alipayGatewayUrl + result.get("body"));
respDto.setPay_data(payData);
//支付订单持久化
this.buildPayOrders(dragonPayBaseReqDto,respDto);
return ResponseDto.success(respDto);
}
private DragonOrders buildPayOrders(DragonPayBaseReqDto dragonPayBaseReqDto,DragonPayBaseRespDto respDto){
DragonOrders orders = new DragonOrders();
// orders.setMid();
orders.setStatus(Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_UNPAID.getCode()));
orders.setCode(respDto.getCode());
orders.setType(dragonPayBaseReqDto.getType());
orders.setPrice(dragonPayBaseReqDto.getPrice());
orders.setName(dragonPayBaseReqDto.getName());
orders.setDetail(dragonPayBaseReqDto.getDetail());
orders.setOrderCode(dragonPayBaseReqDto.getOrderCode());
orders.setClientIp(dragonPayBaseReqDto.getClientIp());
orders.setNotifyUrl(dragonPayBaseReqDto.getNotifyUrl());
orders.setPaymentType(DragonConstant.PayTypeEnum.PAYMENT_TYPE_APP_IAP.getCode());
// orders.setPaymentId();
orders.setPaymentAt(LocalDateTime.now());
// orders.setFinishedAt();
orders.setCreatedAt(LocalDateTime.now());
// orders.setUpdatedAt();
// 修改退款订单
boolean insertResult = sendMySqlRedis(
SqlMapping.get("dragon_orders.insert"),
new Object[]{orders.getStatus(), orders.getCode(), orders.getType()
, orders.getPrice(), orders.getName(), orders.getDetail()
, orders.getOrderCode(), orders.getClientIp()
, orders.getNotifyUrl(), orders.getPaymentType(),
orders.getPaymentId(), orders.getPaymentAt()
, orders.getFinishedAt(), orders.getCreatedAt()
, orders.getUpdatedAt()}
);
return orders;
}
/**
* 给 REDIS 队列发送消息 数据库相关
*
* @param sql sql语句
* @param data 需要操作的数据
* @return
*/
private boolean sendMySqlRedis(String sql, Object[] data) {
try {
LinkedList<String> sqls = new LinkedList<>();
sqls.add(sql);
LinkedList<Object[]> sqlsData = new LinkedList();
sqlsData.add(data);
String sqlData = SqlMapping.gets(sqls, sqlsData);
HashMap<String, String> map = new HashMap<>();
map.put("message", sqlData);
MapRecord<String, String, String> record = StreamRecords.mapBacked(map).withStreamKey(DragonConstant.MysqlRedisQueueEnum.DRAGON_PAY_KEY.getCode());
stringRedisTemplate.opsForStream().add(record);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
return payChannelStrategyContext.getStrategy(dragonPayBaseReqDto.getPayType()).dragonPay(dragonPayBaseReqDto);
}
}
package com.liquidnet.service.dragon.utils;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.dragon.constant.DragonConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.LinkedList;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: MqHandleUtil
* @Package com.liquidnet.service.dragon.utils
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 16:23
*/
@Component
public class MqHandleUtil {
@Autowired
StringRedisTemplate stringRedisTemplate;
/**
* 给 REDIS 队列发送消息 数据库相关
*
* @param sql sql语句
* @param data 需要操作的数据
* @return
*/
public boolean sendMySqlRedis(String sql, Object[] data) {
try {
LinkedList<String> sqls = new LinkedList<>();
sqls.add(sql);
LinkedList<Object[]> sqlsData = new LinkedList();
sqlsData.add(data);
String sqlData = SqlMapping.gets(sqls, sqlsData);
HashMap<String, String> map = new HashMap<>();
map.put("message", sqlData);
MapRecord<String, String, String> record = StreamRecords.mapBacked(map).withStreamKey(DragonConstant.MysqlRedisQueueEnum.DRAGON_PAY_KEY.getCode());
stringRedisTemplate.opsForStream().add(record);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
package com.liquidnet.service.dragon.utils;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: XmlUtil
* @Package com.liquidnet.service.dragon.utils
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/12 11:15
*/
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.InputSource;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 输出xml和解析xml的工具类
*@ClassName:XmlUtil
*/
@Slf4j
public class XmlUtil{
/**
* java 转换成xml
* @Title: toXml
* @Description: TODO
* @param obj 对象实例
* @return String xml字符串
*/
public static String toXml(Object obj){
XStream xstream=new XStream();
// XStream xstream=new XStream(new DomDriver()); //直接用jaxp dom来解释
// XStream xstream=new XStream(new DomDriver("utf-8")); //指定编码解析器,直接用jaxp dom来解释
////如果没有这句,xml中的根元素会是<包.类名>;或者说:注解根本就没生效,所以的元素名就是类的属性
xstream.processAnnotations(obj.getClass()); //通过注解方式的,一定要有这句话
return xstream.toXML(obj);
}
/**
* 将传入xml文本转换成Java对象
* @Title: toBean
* @Description: TODO
* @param xmlStr
* @param cls xml对应的class类
* @return T xml对应的class类的实例对象
*
* 调用的方法实例:PersonBean person=XmlUtil.toBean(xmlStr, PersonBean.class);
*/
public static <T> T toBean(String xmlStr,Class<T> cls){
//注意:不是new Xstream(); 否则报错:java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory
XStream xstream=new XStream(new DomDriver());
xstream.processAnnotations(cls);
T obj=(T)xstream.fromXML(xmlStr);
return obj;
}
/**
* 写到xml文件中去
* @Title: writeXMLFile
* @Description: TODO
* @param obj 对象
* @param absPath 绝对路径
* @param fileName 文件名
* @return boolean
*/
public static boolean toXMLFile(Object obj, String absPath, String fileName ){
String strXml = toXml(obj);
String filePath = absPath + fileName;
File file = new File(filePath);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
log.error("创建{"+ filePath +"}文件失败!!!" + e);
return false ;
}
}// end if
OutputStream ous = null ;
try {
ous = new FileOutputStream(file);
ous.write(strXml.getBytes());
ous.flush();
} catch (Exception e1) {
log.error("写{"+ filePath +"}文件失败!!!" + e1);
return false;
}finally{
if(ous != null )
try {
ous.close();
} catch (IOException e) {
log.error("写{"+ filePath +"}文件关闭输出流异常!!!" + e);
}
}
return true ;
}
public static Map<String, Object> xmlToMap(String xmlDoc) throws DocumentException {
// 创建一个新的字符串
StringReader read = new StringReader(xmlDoc);
// 创建新的输入源SAX 解析器将使用 InputSource 对象来确定如何读取 XML 输入
InputSource source = new InputSource(read);
// 创建一个新的SAXBuilder
SAXReader saxReader = new SAXReader();
Map<String, Object> xmlMap = new HashMap<String, Object>();
Document doc = saxReader.read(source); // 通过输入源构造一个Document
Element root = doc.getRootElement(); // 取的根元素
List<Element> elements = root.elements(); // 得到根元素所有子元素的集合(根元素的子节点,不包括孙子节点)
for (Element et : elements) {
xmlMap.put(et.getName(), et.getText());
}
return xmlMap;
}
// /**
// * 从xml文件读取报文
// * @Title: toBeanFromFile
// * @Description: TODO
// * @param absPath 绝对路径
// * @param fileName 文件名
// * @param cls
// * @throws Exception
// * @return T
// */
// public static <T> T toBeanFromFile(String absPath, String fileName,Class<T> cls) throws Exception{
// String filePath = absPath +fileName;
// InputStream ins = null ;
// try {
// ins = new FileInputStream(new File(filePath ));
// } catch (Exception e) {
// throw new Exception("读{"+ filePath +"}文件失败!", e);
// }
//
// String encode = useEncode(cls);
// XStream xstream=new XStream(new DomDriver(encode));
// xstream.processAnnotations(cls);
// T obj =null;
// try {
// obj = (T)xstream.fromXML(ins);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// throw new Exception("解析{"+ filePath +"}文件失败!",e);
// }
// if(ins != null)
// ins.close();
// return obj;
// }
}
\ No newline at end of file
......@@ -105,12 +105,12 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.2</version>
<version>4.5.22</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dypnsapi</artifactId>
<version>1.1.3</version>
<version>1.2.1</version>
</dependency>
<dependency>
......
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