[Y] 支付完成+抽奖次数

master
taylor.dang 6 years ago
parent cc126c938f
commit c0db0cb297

@ -0,0 +1,90 @@
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();
//只允许pine商户参与该活动
if (order.getIntValue("client_id") != 9) {
return;
}
BigDecimal clearAmount = event.getFinishedEvent().getAudFee();
String channel = order.getString("channel");
if ("Wechat".equals(channel)) {
JSONObject customerRelation = customerMapper.findCustomerByOpenId(order.getString("customer_id"));
if (customerRelation == null) {
customerRelation = customerMapper.findCustomerGlobalpayByOpenId(order.getString("customer_id"));
}
if (customerRelation.getString("kanga_openid") == null) {
return;
}
afterPaymentAddLotteryCount(customerRelation.getString("kanga_openid"), order.getString("order_id"), channel, clearAmount);
}
if ("Alipay".equals(channel)) {
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