commit
ea1e789045
@ -0,0 +1,100 @@
|
|||||||
|
package au.com.royalpay.payment.manage.apps.bean;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/28.
|
||||||
|
*/
|
||||||
|
public class CustomerImpressionQuery {
|
||||||
|
private int payment_times;
|
||||||
|
private BigDecimal amount_begin;
|
||||||
|
private BigDecimal amount_end;
|
||||||
|
private String order;
|
||||||
|
private int client_id;
|
||||||
|
private int page = 1;
|
||||||
|
private int limit = 10;
|
||||||
|
|
||||||
|
public JSONObject toParam(){
|
||||||
|
JSONObject param = new JSONObject();
|
||||||
|
param.put("payment_times",this.payment_times);
|
||||||
|
param.put("amount_begin",this.amount_begin);
|
||||||
|
param.put("amount_end",this.amount_end);
|
||||||
|
param.put("order",this.order);
|
||||||
|
param.put("client_id",this.client_id);
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
public int getPayment_times() {
|
||||||
|
return payment_times;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayment_times(int payment_times) {
|
||||||
|
this.payment_times = payment_times;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getamount_begin() {
|
||||||
|
return amount_begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setamount_begin(BigDecimal amount_begin) {
|
||||||
|
this.amount_begin = amount_begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getamount_end() {
|
||||||
|
return amount_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setamount_end(BigDecimal amount_end) {
|
||||||
|
this.amount_end = amount_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(String order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAmount_begin() {
|
||||||
|
return amount_begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmount_begin(BigDecimal amount_begin) {
|
||||||
|
this.amount_begin = amount_begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAmount_end() {
|
||||||
|
return amount_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmount_end(BigDecimal amount_end) {
|
||||||
|
this.amount_end = amount_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPage() {
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPage(int page) {
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLimit(int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getClient_id() {
|
||||||
|
return client_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_id(int client_id) {
|
||||||
|
this.client_id = client_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
package au.com.royalpay.payment.manage.apps.core;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/28.
|
||||||
|
*/
|
||||||
|
public interface CustomerImpression {
|
||||||
|
|
||||||
|
JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery);
|
||||||
|
|
||||||
|
JSONObject findOne(int client_id,String customer_id);
|
||||||
|
|
||||||
|
void generate(int client_id);
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
package au.com.royalpay.payment.manage.apps.core.impls;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.github.miemiedev.mybatis.paginator.domain.Order;
|
||||||
|
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
|
||||||
|
import com.github.miemiedev.mybatis.paginator.domain.PageList;
|
||||||
|
import com.maxmind.geoip.LookupService;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery;
|
||||||
|
import au.com.royalpay.payment.manage.apps.core.CustomerImpression;
|
||||||
|
import au.com.royalpay.payment.manage.mappers.client.ClientCustomersMapper;
|
||||||
|
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||||
|
import au.com.royalpay.payment.tools.utils.PageListUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/28.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CustomerImpressionImpl implements CustomerImpression {
|
||||||
|
@Resource
|
||||||
|
private ClientCustomersMapper clientCustomersMapper;
|
||||||
|
@Resource
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
@Resource
|
||||||
|
private LookupService lookupService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject listPageble(CustomerImpressionQuery customerImpressionQuery) {
|
||||||
|
PageList<JSONObject> logs = clientCustomersMapper.listCustomerInfo(customerImpressionQuery.toParam(),
|
||||||
|
new PageBounds(customerImpressionQuery.getPage(), customerImpressionQuery.getLimit(), Order.formString(customerImpressionQuery.getOrder())));
|
||||||
|
return PageListUtils.buildPageListResult(logs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject findOne(int client_id, String customer_id) {
|
||||||
|
JSONObject customer = clientCustomersMapper.getClientCustomerWithNull(client_id, customer_id);
|
||||||
|
if(customer==null){
|
||||||
|
throw new BadRequestException("customer info not exist");
|
||||||
|
}
|
||||||
|
JSONObject params = new JSONObject();
|
||||||
|
params.put("customer_id", customer_id);
|
||||||
|
PageList<JSONObject> ordersLast = orderMapper.listOrderByCustomer(params, new PageBounds(1, 1, Order.formString("create_time.desc")));
|
||||||
|
if (!CollectionUtils.isEmpty(ordersLast)) {
|
||||||
|
JSONObject order = ordersLast.get(0);
|
||||||
|
customer.put("last_pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss"));
|
||||||
|
customer.put("last_pay_location", lookupService.getLocation(order.getString("customer_ip")).city);
|
||||||
|
}
|
||||||
|
PageList<JSONObject> ordersFirst = orderMapper.listOrderByCustomer(params, new PageBounds(1, 1, Order.formString("create_time.asc")));
|
||||||
|
if (!CollectionUtils.isEmpty(ordersFirst)) {
|
||||||
|
JSONObject order = ordersFirst.get(0);
|
||||||
|
customer.put("first_pay_time", DateFormatUtils.format(order.getDate("create_time"), "yyyy-MM-dd HH:mm:ss"));
|
||||||
|
customer.put("first_pay_location", lookupService.getLocation(order.getString("customer_ip")).city);
|
||||||
|
|
||||||
|
}
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void generate(int client_id) {
|
||||||
|
JSONObject params = new JSONObject();
|
||||||
|
params.put("client_id", client_id);
|
||||||
|
PageList<JSONObject> lastRecord = clientCustomersMapper.listCustomerInfo(params, new PageBounds(1, 1, Order.formString("create_time.desc")));
|
||||||
|
if (!CollectionUtils.isEmpty(lastRecord)) {
|
||||||
|
params.put("confirm_time", lastRecord.get(0).getDate("creata_time"));
|
||||||
|
}
|
||||||
|
List<JSONObject> orders = orderMapper.listAnalysisClientCustomer(params);
|
||||||
|
Date now = new Date();
|
||||||
|
for (JSONObject order : orders) {
|
||||||
|
if(StringUtils.isEmpty(order.getString("channel"))){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONObject clientCustomerInfo = clientCustomersMapper.getClientCustomerWithNull(client_id, order.getString("customer_id"));
|
||||||
|
if (clientCustomerInfo == null) {
|
||||||
|
JSONObject client_customer = new JSONObject();
|
||||||
|
client_customer.put("client_id", order.getIntValue("client_id"));
|
||||||
|
client_customer.put("customer_id", order.getString("customer_id"));
|
||||||
|
client_customer.put("channel", order.getString("channel"));
|
||||||
|
if (order.getString("alipay_headimg") == null) {
|
||||||
|
client_customer.put("headimg", order.getString("wechat_headimg"));
|
||||||
|
client_customer.put("nick_name", order.getString("wechat_nickname"));
|
||||||
|
} else {
|
||||||
|
client_customer.put("headimg", order.getString("alipay_headimg"));
|
||||||
|
client_customer.put("nick_name", order.getString("alipay_nickname"));
|
||||||
|
}
|
||||||
|
client_customer.put("payment_times", order.getIntValue("payment_times"));
|
||||||
|
client_customer.put("total_amount", order.getBigDecimal("total_amount"));
|
||||||
|
client_customer.put("create_time", now);
|
||||||
|
clientCustomersMapper.insert(client_customer);
|
||||||
|
} else {
|
||||||
|
clientCustomerInfo.put("payment_times", clientCustomerInfo.getIntValue("payment_times") + order.getIntValue("payment_times"));
|
||||||
|
clientCustomerInfo.put("total_amount", clientCustomerInfo.getBigDecimal("total_amount").add(order.getBigDecimal("total_amount")));
|
||||||
|
if (order.getString("alipay_headimg") == null) {
|
||||||
|
clientCustomerInfo.put("headimg", order.getString("wechat_headimg"));
|
||||||
|
clientCustomerInfo.put("nick_name", order.getString("wechat_nickname"));
|
||||||
|
} else {
|
||||||
|
clientCustomerInfo.put("headimg", order.getString("alipay_headimg"));
|
||||||
|
clientCustomerInfo.put("nick_name", order.getString("alipay_nickname"));
|
||||||
|
}
|
||||||
|
clientCustomerInfo.put("channel", order.getString("channel"));
|
||||||
|
clientCustomersMapper.update(clientCustomerInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package au.com.royalpay.payment.manage.apps.web;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.apps.AppController;
|
||||||
|
import au.com.royalpay.payment.manage.apps.bean.CustomerImpressionQuery;
|
||||||
|
import au.com.royalpay.payment.manage.apps.core.CustomerImpression;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@AppController
|
||||||
|
@RequestMapping(value = "/customers/impression")
|
||||||
|
public class CustomerImpressionController {
|
||||||
|
@Resource
|
||||||
|
private CustomerImpression customerImpression;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public JSONObject checkPointsAfterPay(CustomerImpressionQuery customerImpressionQuery) {
|
||||||
|
return customerImpression.listPageble(customerImpressionQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{client_id}/{customer_id}", method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public JSONObject checkPointsAfterPay(@PathVariable int client_id,@PathVariable String customer_id) {
|
||||||
|
return customerImpression.findOne(client_id,customer_id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package au.com.royalpay.payment.manage.mappers.ofei;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by yixian on 2016-06-25.
|
||||||
|
*/
|
||||||
|
@AutoMapper(tablename = "top_up_order", pkName = "id")
|
||||||
|
public interface TopUpOrderMapper {
|
||||||
|
@AutoSql(type = SqlType.INSERT)
|
||||||
|
void save(JSONObject order);
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.UPDATE)
|
||||||
|
void update(JSONObject order);
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.SELECT)
|
||||||
|
JSONObject findById(@Param("id") String id);
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package au.com.royalpay.payment.manage.ofei.core;
|
||||||
|
|
||||||
|
|
||||||
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/7.
|
||||||
|
*/
|
||||||
|
public interface OfeiClient {
|
||||||
|
|
||||||
|
void phoneTopUp(String price, boolean quickTopUp, String topUpDelayTime, String phoneNumber);
|
||||||
|
|
||||||
|
void chekcPhoneNumber(String phoneNumber, String price);
|
||||||
|
|
||||||
|
void flowTopUp(String phoneNumber, String flowValue, String perValue);
|
||||||
|
|
||||||
|
void checkFlow(String phoneNumber, String flowValue, String perValue);
|
||||||
|
|
||||||
|
Element checkOrderStatus(String orderId);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package au.com.royalpay.payment.manage.ofei.core;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/8.
|
||||||
|
*/
|
||||||
|
public interface OfeiServer {
|
||||||
|
void checkOrderForNotify(JSONObject param);
|
||||||
|
|
||||||
|
void checkOrder(String orderId);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,265 @@
|
|||||||
|
package au.com.royalpay.payment.manage.ofei.core.impl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.DocumentException;
|
||||||
|
import org.dom4j.DocumentHelper;
|
||||||
|
import org.dom4j.Element;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ChannelNetworkException;
|
||||||
|
import au.com.royalpay.payment.manage.mappers.ofei.TopUpOrderMapper;
|
||||||
|
import au.com.royalpay.payment.manage.ofei.core.OfeiClient;
|
||||||
|
import au.com.royalpay.payment.tools.codec.MD5Hash;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
||||||
|
|
||||||
|
import cn.yixblog.platform.http.HttpRequestGenerator;
|
||||||
|
import cn.yixblog.platform.http.HttpRequestResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/7.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class OfeiClientImpl implements OfeiClient {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
@Value("${app.ofei.md5-key}")
|
||||||
|
private String md5key;
|
||||||
|
@Value("${app.ofei.pwd}")
|
||||||
|
private String pwd;
|
||||||
|
@Value("${app.ofei.sp-code}")
|
||||||
|
private String spCode;
|
||||||
|
@Resource
|
||||||
|
private TopUpOrderMapper topUpOrderMapper;
|
||||||
|
|
||||||
|
private final String checkUrl = "http://api2.ofpay.com/telcheck.do";
|
||||||
|
private final String topUPUrl = "http://api2.ofpay.com/onlineorder.do";
|
||||||
|
private final String flowTopUPUrl = "http://api2.ofpay.com/flowOrder.do";
|
||||||
|
private final String checkFlowUrl = "http://api2.ofpay.com/flowCheck.do";
|
||||||
|
private final String checkOrderUrl = "http://api2.ofpay.com/queryOrderInfo.do";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void phoneTopUp(String price, boolean quickTopUp, String topUpDelayTime, String phoneNumber) {
|
||||||
|
chekcPhoneNumber(phoneNumber, price);
|
||||||
|
String orderId = "ofei-" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "-" + RandomStringUtils.random(5, true, true);
|
||||||
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
|
String md5Pwd = MD5Hash.hashToHex(pwd);
|
||||||
|
Date now = new Date();
|
||||||
|
params.add(new BasicNameValuePair("userid", spCode));
|
||||||
|
params.add(new BasicNameValuePair("userpws", md5Pwd));
|
||||||
|
params.add(new BasicNameValuePair("cardid", quickTopUp ? "140101" : "170101"));
|
||||||
|
params.add(new BasicNameValuePair("cardnum", String.valueOf(price)));
|
||||||
|
if (!quickTopUp) {
|
||||||
|
params.add(new BasicNameValuePair("mctype", topUpDelayTime));
|
||||||
|
}
|
||||||
|
params.add(new BasicNameValuePair("sporder_id", orderId));
|
||||||
|
params.add(new BasicNameValuePair("sporder_time", DateFormatUtils.format(now, "yyyyMMddHHmmss")));
|
||||||
|
params.add(new BasicNameValuePair("game_userid", phoneNumber));
|
||||||
|
|
||||||
|
saveOrder(orderId, now, "1", price, phoneNumber);
|
||||||
|
HttpRequestGenerator req = initRequest(topUPUrl, signAndEncryptForm(params), RequestMethod.GET);
|
||||||
|
Element respXml = executeRequestXML(req, "ofei phone top up fail");
|
||||||
|
handleResponse(orderId, respXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleResponse(String orderId, Element respXml) {
|
||||||
|
JSONObject detail = new JSONObject();
|
||||||
|
if ("1".equals(respXml.elementText("retcode"))) {
|
||||||
|
detail.put("cardname", respXml.elementText("cardname"));
|
||||||
|
String gameState = respXml.elementText("game_state");
|
||||||
|
switch (gameState) {
|
||||||
|
case "1":
|
||||||
|
updateOrder(orderId, "1", detail);
|
||||||
|
break;
|
||||||
|
case "0":
|
||||||
|
updateOrder(orderId, "10", detail);
|
||||||
|
break;
|
||||||
|
case "9":
|
||||||
|
updateOrder(orderId, "20", detail);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
detail.put("err_msg",respXml.elementText("err_msg"));
|
||||||
|
updateOrder(orderId,"99",detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void chekcPhoneNumber(String phoneNumber, String price) {
|
||||||
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
|
params.add(new BasicNameValuePair("userid", spCode));
|
||||||
|
params.add(new BasicNameValuePair("phoneno", phoneNumber));
|
||||||
|
params.add(new BasicNameValuePair("price", String.valueOf(price)));
|
||||||
|
HttpRequestGenerator req = initRequest(checkUrl, params, RequestMethod.GET);
|
||||||
|
String respStr = executeRequestString(req, "ofei phoneNumberCheck");
|
||||||
|
String resultCode = respStr.substring(0, respStr.indexOf("#"));
|
||||||
|
switch (resultCode) {
|
||||||
|
case "1":
|
||||||
|
break;
|
||||||
|
case "321":
|
||||||
|
throw new BadRequestException("暂时不支持此类手机号的充值");
|
||||||
|
case "11":
|
||||||
|
throw new BadRequestException("运营商地区维护,暂不能充值");
|
||||||
|
default:
|
||||||
|
throw new ServerErrorException("系统异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flowTopUp(String phoneNumber, String flowValue, String perValue) {
|
||||||
|
checkFlow(phoneNumber, flowValue, perValue);
|
||||||
|
String orderId = "ofei-" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "-" + RandomStringUtils.random(5, true, true);
|
||||||
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
|
String md5Pwd = MD5Hash.hashToHex(pwd);
|
||||||
|
params.add(new BasicNameValuePair("userid", spCode));
|
||||||
|
params.add(new BasicNameValuePair("userpws", md5Pwd));
|
||||||
|
params.add(new BasicNameValuePair("phoneno", phoneNumber));
|
||||||
|
params.add(new BasicNameValuePair("perValue", perValue));
|
||||||
|
params.add(new BasicNameValuePair("flowValue", flowValue));
|
||||||
|
params.add(new BasicNameValuePair("range", "2"));
|
||||||
|
params.add(new BasicNameValuePair("effectStartTime", "1"));
|
||||||
|
params.add(new BasicNameValuePair("effectTime", "1"));
|
||||||
|
params.add(new BasicNameValuePair("netType", "4G"));
|
||||||
|
params.add(new BasicNameValuePair("sporderId", orderId));
|
||||||
|
saveOrder(orderId, new Date(), "2", perValue, phoneNumber);
|
||||||
|
HttpRequestGenerator req = initRequest(flowTopUPUrl, signAndEncryptForm(params), RequestMethod.GET);
|
||||||
|
Element respXml = executeRequestXML(req, "ofei flowTopUp");
|
||||||
|
handleResponse(orderId, respXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkFlow(String phoneNumber, String flowValue, String perValue) {
|
||||||
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
|
String md5Pwd = MD5Hash.hashToHex(pwd);
|
||||||
|
params.add(new BasicNameValuePair("userid", spCode));
|
||||||
|
params.add(new BasicNameValuePair("userpws", md5Pwd));
|
||||||
|
params.add(new BasicNameValuePair("phoneno", phoneNumber));
|
||||||
|
params.add(new BasicNameValuePair("perValue", perValue));
|
||||||
|
params.add(new BasicNameValuePair("flowValue", flowValue));
|
||||||
|
params.add(new BasicNameValuePair("range", "2"));
|
||||||
|
params.add(new BasicNameValuePair("effectStartTime", "1"));
|
||||||
|
params.add(new BasicNameValuePair("effectTime", "1"));
|
||||||
|
params.add(new BasicNameValuePair("netType", "4G"));
|
||||||
|
HttpRequestGenerator req = initRequest(checkFlowUrl, signAndEncryptForm(params), RequestMethod.GET);
|
||||||
|
Element respXml = executeRequestXML(req, "ofei flowCheck");
|
||||||
|
String returnCode = respXml.elementText("retcode");
|
||||||
|
switch (returnCode) {
|
||||||
|
case "1":
|
||||||
|
break;
|
||||||
|
case "11":
|
||||||
|
throw new BadRequestException(respXml.elementText("err_msg"));
|
||||||
|
default:
|
||||||
|
throw new ServerErrorException("系统异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Element checkOrderStatus(String orderId) {
|
||||||
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
|
String md5Pwd = MD5Hash.hashToHex(pwd);
|
||||||
|
params.add(new BasicNameValuePair("userid", spCode));
|
||||||
|
params.add(new BasicNameValuePair("userpws", md5Pwd));
|
||||||
|
params.add(new BasicNameValuePair("sporder_id", orderId));
|
||||||
|
HttpRequestGenerator req = initRequest(checkOrderUrl,signAndEncryptForm(params), RequestMethod.GET);
|
||||||
|
return executeRequestXML(req,"ofei check order status error");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<NameValuePair> signAndEncryptForm(List<NameValuePair> params) {
|
||||||
|
String signStr = "";
|
||||||
|
for (NameValuePair pair : params) {
|
||||||
|
if ("md5Str,retUrl,version,mctype,md5_str,ret_url,buyNum".contains(pair.getName())) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
signStr += pair.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
signStr += md5key;
|
||||||
|
params.add(new BasicNameValuePair("md5_str", MD5Hash.hashToHex(signStr).toUpperCase()));
|
||||||
|
params.add(new BasicNameValuePair("version", "6.0"));
|
||||||
|
params.add(new BasicNameValuePair("md5Str", MD5Hash.hashToHex(signStr).toUpperCase()));
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpRequestGenerator initRequest(String url, List<NameValuePair> params, RequestMethod requestMethod) {
|
||||||
|
HttpRequestGenerator gen = new HttpRequestGenerator(url, requestMethod);
|
||||||
|
for (NameValuePair pair : params) {
|
||||||
|
gen.addQueryString(pair.getName(), pair.getValue());
|
||||||
|
}
|
||||||
|
return gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Element executeRequestXML(HttpRequestGenerator gen, String errMsg) {
|
||||||
|
try {
|
||||||
|
HttpRequestResult res = gen.execute();
|
||||||
|
if (res.isSuccess()) {
|
||||||
|
byte[] respArr = res.getResponseContentBytes();
|
||||||
|
String respStr = new String(respArr, "GB2312");
|
||||||
|
logger.debug("ofei server response:" + respStr);
|
||||||
|
Document respXml = DocumentHelper.parseText(respStr);
|
||||||
|
Element respRoot = respXml.getRootElement();
|
||||||
|
return respRoot;
|
||||||
|
} else {
|
||||||
|
throw new ChannelNetworkException(errMsg + "-->Network Error:" + res.getStatusCode());
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException | DocumentException | IOException e) {
|
||||||
|
throw new ChannelNetworkException(errMsg + "-->Network Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String executeRequestString(HttpRequestGenerator gen, String errMsg) {
|
||||||
|
try {
|
||||||
|
HttpRequestResult res = gen.execute();
|
||||||
|
if (res.isSuccess()) {
|
||||||
|
byte[] respArr = res.getResponseContentBytes();
|
||||||
|
String respStr = new String(respArr, "GB2312");
|
||||||
|
logger.debug("ofei server response:" + respStr);
|
||||||
|
return respStr;
|
||||||
|
} else {
|
||||||
|
throw new ChannelNetworkException(errMsg + "-->Network Error:" + res.getStatusCode());
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException | IOException e) {
|
||||||
|
throw new ChannelNetworkException(errMsg + "-->Network Error", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveOrder(String orderId, Date now, String type, String price, String customerNumber) {
|
||||||
|
JSONObject order = new JSONObject();
|
||||||
|
order.put("id", orderId);
|
||||||
|
order.put("create_time", now);
|
||||||
|
order.put("type", type);
|
||||||
|
order.put("amount", price);
|
||||||
|
order.put("customer_number", customerNumber);
|
||||||
|
order.put("status", "0");
|
||||||
|
topUpOrderMapper.save(order);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateOrder(String orderId, String status, JSONObject detail) {
|
||||||
|
JSONObject record = new JSONObject();
|
||||||
|
record.put("id", orderId);
|
||||||
|
record.put("status", status);
|
||||||
|
record.put("detail", detail.toJSONString());
|
||||||
|
topUpOrderMapper.update(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package au.com.royalpay.payment.manage.ofei.core.impl;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.dom4j.Element;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.mappers.ofei.TopUpOrderMapper;
|
||||||
|
import au.com.royalpay.payment.manage.ofei.core.OfeiClient;
|
||||||
|
import au.com.royalpay.payment.manage.ofei.core.OfeiServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/8.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class OfeiServceImpl implements OfeiServer {
|
||||||
|
@Resource
|
||||||
|
private TopUpOrderMapper topUpOrderMapper;
|
||||||
|
@Resource
|
||||||
|
private OfeiClient ofeiClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkOrderForNotify(JSONObject param) {
|
||||||
|
JSONObject order = topUpOrderMapper.findById(param.getString("orderId"));
|
||||||
|
if (order == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String ret_code = param.getString("ret_code");
|
||||||
|
switch (ret_code) {
|
||||||
|
case "1":
|
||||||
|
order.put("status", "1");
|
||||||
|
break;
|
||||||
|
case "9":
|
||||||
|
order.put("status", 20);
|
||||||
|
JSONObject detail = new JSONObject();
|
||||||
|
detail.put("err_msg", param.getString("err_msg"));
|
||||||
|
order.put("detail", detail.toJSONString());
|
||||||
|
}
|
||||||
|
topUpOrderMapper.update(order);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkOrder(String orderId) {
|
||||||
|
JSONObject order = topUpOrderMapper.findById(orderId);
|
||||||
|
if (order==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Element orderStats = ofeiClient.checkOrderStatus(orderId);
|
||||||
|
JSONObject detail = new JSONObject();
|
||||||
|
if ("1".equals(orderStats.elementText("retcode"))) {
|
||||||
|
detail.put("cardname", orderStats.elementText("cardname"));
|
||||||
|
order.put("detail",detail.toJSONString());
|
||||||
|
String gameState = orderStats.elementText("game_state");
|
||||||
|
switch (gameState) {
|
||||||
|
case "1":
|
||||||
|
order.put("status","1");
|
||||||
|
break;
|
||||||
|
case "0":
|
||||||
|
order.put("status","10");
|
||||||
|
break;
|
||||||
|
case "9":
|
||||||
|
order.put("status","20");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
order.put("status","99");
|
||||||
|
order.put("detail",order.getJSONObject("detail").put("err_msg",orderStats.elementText("err_msg")));
|
||||||
|
detail.put("err_msg",orderStats.elementText("err_msg"));
|
||||||
|
}
|
||||||
|
topUpOrderMapper.update(order);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package au.com.royalpay.payment.manage.ofei.web;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.ofei.core.OfeiServer;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/8.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/ofei/notice")
|
||||||
|
public class OfeiNotifyController {
|
||||||
|
@Resource
|
||||||
|
private OfeiServer ofeiServer;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{order_id}",method = {RequestMethod.GET, RequestMethod.POST})
|
||||||
|
public void listNotices(@PathVariable String order_id, @RequestParam String ret_code, @RequestParam String ordersuccesstime, @RequestParam String err_msg) {
|
||||||
|
JSONObject params =new JSONObject();
|
||||||
|
params.put("orderId",order_id);
|
||||||
|
params.put("ret_code",ret_code);
|
||||||
|
params.put("ordersuccesstime",ordersuccesstime);
|
||||||
|
params.put("err_msg",err_msg);
|
||||||
|
ofeiServer.checkOrderForNotify(params);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package au.com.royalpay.payment.manage.ofei.web;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.ofei.core.OfeiClient;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wangning on 2017/12/8.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/phone_top_up")
|
||||||
|
public class PhoneTopUpController {
|
||||||
|
@Resource
|
||||||
|
private OfeiClient ofeiClient;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/recharge",method = {RequestMethod.GET, RequestMethod.POST})
|
||||||
|
public void listNotices(@RequestParam String phoneNumber, @RequestParam String amount) {
|
||||||
|
ofeiClient.phoneTopUp(amount,true,null,phoneNumber);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="au.com.royalpay.payment.manage.mappers.client.ClientCustomersMapper">
|
||||||
|
<select id="listCustomerInfo" resultType="com.alibaba.fastjson.JSONObject">
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM sys_clients_customers
|
||||||
|
where
|
||||||
|
client_id = #{client_id}
|
||||||
|
<if test="payment_times >0">
|
||||||
|
and payment_times = #{payment_times}
|
||||||
|
</if>
|
||||||
|
<if test="amount_begin != null">
|
||||||
|
and total_amount > #{amount_begin}
|
||||||
|
</if>
|
||||||
|
<if test="amount_end != null">
|
||||||
|
and total_amount <=#{amount_end}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getClientCustomerWithNull" resultType="com.alibaba.fastjson.JSONObject">
|
||||||
|
select *
|
||||||
|
FROM sys_clients_customers
|
||||||
|
where client_id = #{client_id}
|
||||||
|
and customer_id = #{customer_id}
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</mapper>
|
@ -0,0 +1,36 @@
|
|||||||
|
<section class="content-header">
|
||||||
|
<h1>Phone Top Up</h1>
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li>
|
||||||
|
<i class="fa fa-cog"></i> Basic Config
|
||||||
|
</li>
|
||||||
|
<li><a ui-sref="^">Dev Tools</a></li>
|
||||||
|
<li class="active">phone top up</li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<div class="box-solid">
|
||||||
|
<div class="box box-warning">
|
||||||
|
<div class="box-header">
|
||||||
|
<form role="form" style="margin:0px auto;width: 50%">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Phone Number</label>
|
||||||
|
<input ng-model="params.phoneNumber" name="code" class="form-control" type="text"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Amount</label>
|
||||||
|
<input ng-model="params.amount" class="form-control" type="text" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<button class="btn btn-primary btn-block" ng-click="topUp()">commit</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
Loading…
Reference in new issue