diff --git a/src/db/modify.sql b/src/db/modify.sql index 7328ed984..73289f97f 100644 --- a/src/db/modify.sql +++ b/src/db/modify.sql @@ -108,6 +108,11 @@ ALTER TABLE `sys_accounts` ALTER TABLE `sys_clients_audit_process` MODIFY COLUMN `operator_id` varchar(50) NOT NULL ; +ALTER TABLE `pmt_refunds` + MODIFY COLUMN `operator_id` varchar(50) DEFAULT NULL COMMENT '退款操作者账号'; + +ALTER TABLE `sys_clients_apply` + MODIFY COLUMN `short_name` varchar(100) DEFAULT NULL COMMENT '公司简称'; diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/bean/CustomerImpressionQuery.java b/src/main/java/au/com/royalpay/payment/manage/apps/bean/CustomerImpressionQuery.java new file mode 100644 index 000000000..a177232b0 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/bean/CustomerImpressionQuery.java @@ -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; + } +} + diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/core/CustomerImpression.java b/src/main/java/au/com/royalpay/payment/manage/apps/core/CustomerImpression.java new file mode 100644 index 000000000..5ec9f7006 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/core/CustomerImpression.java @@ -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); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImpl.java b/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImpl.java new file mode 100644 index 000000000..b09d03387 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/core/impls/CustomerImpressionImpl.java @@ -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 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 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 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 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 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); + } + } + } + +} \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/apps/web/CustomerImpressionController.java b/src/main/java/au/com/royalpay/payment/manage/apps/web/CustomerImpressionController.java new file mode 100644 index 000000000..e71584d85 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/apps/web/CustomerImpressionController.java @@ -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); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java index 6b3b95ba5..52257fdfe 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.java @@ -1,10 +1,14 @@ package au.com.royalpay.payment.manage.mappers.client; +import org.apache.ibatis.annotations.Param; + +import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; + import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; import cn.yixblog.support.mybatis.autosql.annotations.SqlType; -import com.alibaba.fastjson.JSONObject; -import org.apache.ibatis.annotations.Param; /** * Created by yuan on 2017/9/12. @@ -14,9 +18,14 @@ public interface ClientCustomersMapper { @AutoSql(type = SqlType.SELECT) public JSONObject getClientCustomer(@Param("client_id") int client_id, @Param("customer_id") String customer_id); + public JSONObject getClientCustomerWithNull(@Param("client_id") int client_id, @Param("customer_id") String customer_id); + @AutoSql(type = SqlType.INSERT) public void insert(JSONObject obj); @AutoSql(type = SqlType.UPDATE) public void update(JSONObject obj); + + PageList listCustomerInfo(JSONObject params, PageBounds pageBounds); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/ofei/TopUpOrderMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/ofei/TopUpOrderMapper.java new file mode 100644 index 000000000..253b4799f --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/ofei/TopUpOrderMapper.java @@ -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); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java index 5300d7f1f..3c7f8f001 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java @@ -75,4 +75,6 @@ public interface OrderMapper { List listPaid(JSONObject params, PageBounds pageBounds); List listOrdersByClientsNoPages(JSONObject params); + + List listAnalysisClientCustomer(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/ofei/core/OfeiClient.java b/src/main/java/au/com/royalpay/payment/manage/ofei/core/OfeiClient.java new file mode 100644 index 000000000..f16a47b7b --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/ofei/core/OfeiClient.java @@ -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); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/ofei/core/OfeiServer.java b/src/main/java/au/com/royalpay/payment/manage/ofei/core/OfeiServer.java new file mode 100644 index 000000000..842cc7400 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/ofei/core/OfeiServer.java @@ -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); + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiClientImpl.java b/src/main/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiClientImpl.java new file mode 100644 index 000000000..597c10a2d --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiClientImpl.java @@ -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 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 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 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 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 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 signAndEncryptForm(List 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 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); + } + + + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiServceImpl.java b/src/main/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiServceImpl.java new file mode 100644 index 000000000..f4ab6b2bb --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/ofei/core/impl/OfeiServceImpl.java @@ -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); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/ofei/web/OfeiNotifyController.java b/src/main/java/au/com/royalpay/payment/manage/ofei/web/OfeiNotifyController.java new file mode 100644 index 000000000..7acb3e52f --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/ofei/web/OfeiNotifyController.java @@ -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); + } +} \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/ofei/web/PhoneTopUpController.java b/src/main/java/au/com/royalpay/payment/manage/ofei/web/PhoneTopUpController.java new file mode 100644 index 000000000..896f2712c --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/ofei/web/PhoneTopUpController.java @@ -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); + } +} \ No newline at end of file diff --git a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java index 7de883812..960b56de9 100644 --- a/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/tradelog/core/impls/TradeLogServiceImpl.java @@ -379,6 +379,8 @@ public class TradeLogServiceImpl implements TradeLogService { obj.put("client_id", orderLog.getInteger("client_id")); obj.put("customer_id", orderLog.getString("customer_id")); obj.put("name_remak", name_remark); + obj.put("channel",order.getString("channel")); + obj.put("create_time",new Date()); JSONObject client_coustom = clientCustomersMapper.getClientCustomer(orderLog.getInteger("client_id"), orderLog.getString("customer_id")); if (null == client_coustom) { clientCustomersMapper.insert(obj); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ca4a94378..548187901 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,6 +2,8 @@ server.port=5000 spring.profiles.active=dev,alipay,bestpay,jd,wechat +env.company=RoyalPay + multipart.max-file-size=10Mb spring.datasource.test-while-idle=true @@ -87,4 +89,8 @@ apple.message.apns.password=F1b5*ChJPp73 spring.thymeleaf.mode=LEGACYHTML5 app.mpsupport.host=https://mp.royalpay.com.au -app.foreign-currency=AUD \ No newline at end of file +app.foreign-currency=AUD + +app.ofei.md5-key=Khjx6wejblaJzmG0JBWFlPFKAUxhFIXQ +app.ofei.pwd=aomi@8888 +app.ofei.sp-code=A1407200 \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml new file mode 100644 index 000000000..1de5ec0bb --- /dev/null +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/client/ClientCustomersMapper.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml index 2bc38a6c6..c6308a28f 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml @@ -529,6 +529,28 @@ + + +
+ + +
+
+ +
+ + + + + + + diff --git a/src/main/ui/static/config/devtools/templates/root.html b/src/main/ui/static/config/devtools/templates/root.html index 076ad5064..6e18a1a0d 100644 --- a/src/main/ui/static/config/devtools/templates/root.html +++ b/src/main/ui/static/config/devtools/templates/root.html @@ -62,6 +62,11 @@ 商品库 + + + + Phone Top Up +