支付完成后添加抽奖次数

master
yangkai 6 years ago
parent 5c6125c14a
commit 8bf48d053e

@ -0,0 +1,85 @@
package au.com.royalpay.payment.manage.customers.core.impls;
import au.com.royalpay.payment.core.events.AfterPaymentFinishEvent;
import au.com.royalpay.payment.manage.mappers.system.CustomerMapper;
import au.com.royalpay.payment.tools.threadpool.RoyalThreadPoolExecutor;
import cn.yixblog.platform.http.HttpRequestGenerator;
import cn.yixblog.platform.http.HttpRequestResult;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.Resource;
import java.math.BigDecimal;
@Service
public class CustomerLotteryCountServiceImpl implements ApplicationListener<AfterPaymentFinishEvent> {
private Logger logger = LoggerFactory.getLogger(getClass());
@Value("${app.customer.host}")
private String CUSTOMER_HOST;
@Value("${customer.app.appid}")
private String CUSTOMER_APP_ID;
@Value("${customer.app.auth-code}")
private String CUSTOMER_AUTH_CODE;
@Resource
private RoyalThreadPoolExecutor royalThreadPoolExecutor;
@Resource
private CustomerMapper customerMapper;
@Override
public void onApplicationEvent(AfterPaymentFinishEvent event) {
final JSONObject order = event.getFinishedEvent().getOrder();
BigDecimal clearAmount = event.getFinishedEvent().getAudFee();
String channel = order.getString("channel");
if ("Wechat".equals(channel)) {
JSONObject customerRelation = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
if (customerRelation.getString("kanga_openid") == null) {
return;
}
royalThreadPoolExecutor.execute(() -> afterPaymentAddLotteryCount(customerRelation.getString("kanga_openid"),
order.getString("order_id"), channel, clearAmount));
}
if ("Alipay".equals(channel)) {
royalThreadPoolExecutor.execute(() -> afterPaymentAddLotteryCount(order.getString("customer_id"),
order.getString("order_id"), channel, clearAmount));
}
}
private void afterPaymentAddLotteryCount(String id, String orderId, String channel, BigDecimal clearAmount) {
String timestamp = System.currentTimeMillis() + "";
String base = CUSTOMER_APP_ID + timestamp + CUSTOMER_AUTH_CODE;
String sign = DigestUtils.sha256Hex(base).toLowerCase();
String uri = UriComponentsBuilder.fromHttpUrl(CUSTOMER_HOST + "activity/luck_draw/payment/lottery/count")
.queryParam("appid", CUSTOMER_APP_ID)
.queryParam("timestamp", timestamp)
.queryParam("sign", sign)
.queryParam("id", id)
.queryParam("orderId", orderId)
.queryParam("channel", channel)
.queryParam("amount", clearAmount)
.toUriString();
HttpRequestGenerator gen = new HttpRequestGenerator(uri, RequestMethod.POST);
try {
HttpRequestResult result = gen.execute();
if (result.isSuccess()) {
int statusCode = result.getStatusCode();
if (statusCode == 200) {
logger.info("抽奖次数添加成功");
}
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}
Loading…
Cancel
Save