|
|
|
@ -0,0 +1,105 @@
|
|
|
|
|
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 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;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class CustomerHalloweenCountServiceImpl 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 CustomerMapper customerMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onApplicationEvent(AfterPaymentFinishEvent event) {
|
|
|
|
|
final JSONObject order = event.getFinishedEvent().getOrder();
|
|
|
|
|
//判断是否是pine测试商户,若不是则判断是否在活动时间
|
|
|
|
|
if (order.getIntValue("client_id") != 9) {
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
Date newDay = new Date();
|
|
|
|
|
try {
|
|
|
|
|
if (newDay.compareTo(sdf.parse("2018-10-31 00:00:00")) < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (newDay.compareTo(sdf.parse("2018-11-02 00:00:00")) > 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
afterPaymentAddHalloweenCount(customerRelation.getString("kanga_openid"), order.getString("order_id"), customerRelation.getString("redpack_openid"),channel, clearAmount);
|
|
|
|
|
}
|
|
|
|
|
if ("Alipay".equals(channel)) {
|
|
|
|
|
afterPaymentAddHalloweenCount(order.getString("customer_id"), order.getString("order_id"), "alipay",channel, clearAmount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void afterPaymentAddHalloweenCount(String id, String orderId,String redPackId, 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/halloween/payment/orders")
|
|
|
|
|
.queryParam("appid", CUSTOMER_APP_ID)
|
|
|
|
|
.queryParam("timestamp", timestamp)
|
|
|
|
|
.queryParam("sign", sign)
|
|
|
|
|
.queryParam("id", id)
|
|
|
|
|
.queryParam("orderId", orderId)
|
|
|
|
|
.queryParam("channel", channel)
|
|
|
|
|
.queryParam("amount", clearAmount)
|
|
|
|
|
.queryParam("redpackId", redPackId)
|
|
|
|
|
.toUriString();
|
|
|
|
|
if(clearAmount.compareTo(new BigDecimal("1.99"))<0){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|