Merge branch 'ofeiQB' into develop

master
wangning 7 years ago
commit e322e6a631

@ -13,6 +13,8 @@ public class PhoneTopUpQuery {
private String phone;
private String type;
private int page = 1;
private int limit = 10;
@ -57,11 +59,20 @@ public class PhoneTopUpQuery {
this.phone = phone;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public JSONObject toParam(){
JSONObject param = new JSONObject();
param.put("status",this.status);
param.put("amount",this.amount);
param.put("customer_number",this.phone);
param.put("type",this.type);
return param;
}
}

@ -17,4 +17,7 @@ public interface OfeiClient {
void checkFlow(String phoneNumber, String flowValue, String perValue);
Element checkOrderStatus(String orderId);
void qbTopUp(String price, String qqNumber);
}

@ -12,4 +12,7 @@ public interface OfeiServer {
void phoneTopUp(String price, boolean quickTopUp, String topUpDelayTime, String phoneNumber);
void qbTopUp(String price, String phoneNumber);
}

@ -4,7 +4,9 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@ -27,6 +29,7 @@ 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.manage.ofei.enums.OfeiType;
import au.com.royalpay.payment.tools.codec.MD5Hash;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
@ -55,6 +58,14 @@ public class OfeiClientImpl implements OfeiClient {
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";
private final String qbTopUpUrl = "http://api2.ofpay.com/onlineorder.do";
private static final Map<String,String> qbCardId = new HashMap<>();
static {
qbCardId.put("10","220615");
qbCardId.put("30","220617");
qbCardId.put("50","220698");
qbCardId.put("100","220699");
}
@Override
public void phoneTopUp(String price, boolean quickTopUp, String topUpDelayTime, String phoneNumber) {
@ -75,13 +86,13 @@ public class OfeiClientImpl implements OfeiClient {
params.add(new BasicNameValuePair("game_userid", phoneNumber));
params.add(new BasicNameValuePair("ret_url", "https://mpay.royalpay.com.au/ofei/notice/"+orderId));
saveOrder(orderId, now, "1", price, phoneNumber);
saveOrder(orderId, now, OfeiType.PHONE.getMask(), price, phoneNumber);
HttpRequestGenerator req = initRequest(topUPUrl, signAndEncryptForm(params), RequestMethod.GET);
Element respXml = executeRequestXML(req, "ofei phone top up fail");
handleResponse(orderId, respXml,phoneNumber);
}
private void handleResponse(String orderId, Element respXml,String phoneNumber) {
private void handleResponse(String orderId, Element respXml,String customerNumber) {
JSONObject detail = new JSONObject();
if ("1".equals(respXml.elementText("retcode"))) {
detail.put("cardname", respXml.elementText("cardname"));
@ -103,7 +114,7 @@ public class OfeiClientImpl implements OfeiClient {
}else {
detail.put("err_msg",respXml.elementText("err_msg"));
updateOrder(orderId,"99",detail);
logger.debug("phone->"+phoneNumber+" top up error orderId->"+orderId);
logger.debug("Customer NUmber->"+customerNumber+" top up error orderId->"+orderId);
throw new ServerErrorException("System error");
}
}
@ -145,7 +156,7 @@ public class OfeiClientImpl implements OfeiClient {
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);
saveOrder(orderId, new Date(), OfeiType.FLOW.getMask(), perValue, phoneNumber);
HttpRequestGenerator req = initRequest(flowTopUPUrl, signAndEncryptForm(params), RequestMethod.GET);
Element respXml = executeRequestXML(req, "ofei flowTopUp");
handleResponse(orderId, respXml,phoneNumber);
@ -188,6 +199,35 @@ public class OfeiClientImpl implements OfeiClient {
return executeRequestXML(req,"ofei check order status error");
}
@Override
public void qbTopUp(String price, String qqNumber) {
if(price.contains(".")){
throw new BadRequestException("Invalid 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));
if(qbCardId.containsKey(price)){
params.add(new BasicNameValuePair("cardid", qbCardId.get(price)));
params.add(new BasicNameValuePair("cardnum", "1"));
}else {
params.add(new BasicNameValuePair("cardid", "220612"));
params.add(new BasicNameValuePair("cardnum", price));
}
params.add(new BasicNameValuePair("sporder_id", orderId));
params.add(new BasicNameValuePair("sporder_time", DateFormatUtils.format(now, "yyyyMMddHHmmss")));
params.add(new BasicNameValuePair("game_userid", qqNumber));
params.add(new BasicNameValuePair("ret_url", "https://mpay.royalpay.com.au/ofei/notice/"+orderId));
saveOrder(orderId, now, OfeiType.QB.getMask(), price, qqNumber);
HttpRequestGenerator req = initRequest(qbTopUpUrl, signAndEncryptForm(params), RequestMethod.POST);
Element respXml = executeRequestXML(req, "ofei QB top up fail");
handleResponse(orderId, respXml,qqNumber);
}
private List<NameValuePair> signAndEncryptForm(List<NameValuePair> params) {
String signStr = "";
for (NameValuePair pair : params) {

@ -94,4 +94,16 @@ public class OfeiServceImpl implements OfeiServer {
stringRedisTemplate.boundValueOps(reidsCheckCodeKey).set(bindId, 10, TimeUnit.MINUTES);
}
@Override
public void qbTopUp(String price, String qqNumber) {
String reidsCheckCodeKey = "qbtopup"+qqNumber;
String value = stringRedisTemplate.boundValueOps(reidsCheckCodeKey).get();
if (!StringUtils.isEmpty(value)) {
throw new ForbiddenException("A phone number can only be recharged in 10 minutes");
}
ofeiClient.qbTopUp(price,qqNumber);
String bindId = RandomStringUtils.random(6, false, true);
stringRedisTemplate.boundValueOps(reidsCheckCodeKey).set(bindId, 10, TimeUnit.MINUTES);
}
}

@ -0,0 +1,21 @@
package au.com.royalpay.payment.manage.ofei.enums;
/**
* Created by wangning on 30/01/2018.
*/
public enum OfeiType {
PHONE("1"), // 话费
FLOW("2"), // 流量
QB("3");// Q币
private String mask;
OfeiType(String mask) {
this.mask = mask;
}
public String getMask() {
return mask;
}
}

@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.ofei.web;
import au.com.royalpay.payment.manage.ofei.bean.PhoneTopUpQuery;
import au.com.royalpay.payment.manage.ofei.core.OfeiServer;
import au.com.royalpay.payment.manage.ofei.core.PhoneTopUpService;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import com.alibaba.fastjson.JSONObject;
@ -17,7 +18,7 @@ import javax.annotation.Resource;
* Created by wangning on 2017/12/8.
*/
@RestController
@RequestMapping("/phone_top_up")
@RequestMapping("/top_up")
public class PhoneTopUpController {
@Resource
private OfeiServer ofeiServer;
@ -25,8 +26,17 @@ public class PhoneTopUpController {
private PhoneTopUpService phoneTopUpService;
@RequestMapping(value = "/recharge", method = { RequestMethod.GET, RequestMethod.POST })
public void recharge(@RequestParam String phoneNumber, @RequestParam String amount) {
ofeiServer.phoneTopUp(amount,true,null,phoneNumber);
public void recharge(@RequestParam String customerNumber, @RequestParam String amount, @RequestParam(defaultValue = "1") String type) {
switch (type) {
case "1":
ofeiServer.phoneTopUp(amount, true, null, customerNumber);
break;
case "3":
ofeiServer.qbTopUp(amount, customerNumber);
break;
default:
throw new BadRequestException("unknow top up type");
}
}
@RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.GET })

@ -22,6 +22,9 @@
<if test="amount > 0">
amount = #{amount}
</if>
<if test="type != null">
`type` = #{type}
</if>
</where>
</select>
</mapper>

@ -44,12 +44,12 @@ define(['angular', 'uiRouter', 'static/commons/angular-ueditor'], function (angu
app.controller('cmsRootCtrl', ['$scope', function ($scope) {
}]);
app.controller('CmsPhonetopupCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {
app.controller('CmsPhonetopupCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.queryParams = {};
$scope.pagination = {};
$scope.topUp = function () {
var params = angular.copy($scope.params);
$http.get('/phone_top_up/recharge',{params: params}).then(function (resp) {
$http.get('/top_up/recharge',{params: params}).then(function (resp) {
alert('ok');
}, function (resp) {
alert(resp.data.message);
@ -68,7 +68,10 @@ define(['angular', 'uiRouter', 'static/commons/angular-ueditor'], function (angu
if(params.status==''|| params.status==null){
delete params.status;
}
$http.get('/phone_top_up/list',{params: params}).then(function (resp) {
if(params.type==''|| params.type==null){
delete params.type;
}
$http.get('/top_up/list',{params: params}).then(function (resp) {
$scope.orders = resp.data.data;
$scope.pagination = resp.data.pagination;
})
@ -133,6 +136,8 @@ define(['angular', 'uiRouter', 'static/commons/angular-ueditor'], function (angu
return '话费充值';
case '2':
return '流量';
case '3':
return 'QB';
}
}
});

@ -17,8 +17,24 @@
<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"
<label>Type</label>
<select class="form-control" name="industry"
ng-model="params.type"
id="industry-input" required>
<option value="">Please Choose</option>
<option value="1">Phone</option>
<option value="2">Flow</option>
<option value="3">QB</option>
</select>
<div ng-messages="params.type.$error"
ng-if="params.type.$dirty">
<p class="small text-danger" ng-message="required">Required
Field</p>
</div>
</div>
<div class="form-group">
<label>Customer Number</label>
<input ng-model="params.customerNumber" name="code"
class="form-control" type="text"/>
</div>
<div class="form-group">
@ -55,13 +71,27 @@
<a role="button" ng-class="{'bg-primary':queryParams.status=='30'}"
ng-click="queryParams.status='30';listTopUpOrders(1)">Refund</a> |
<a role="button" ng-class="{'bg-primary':queryParams.status=='20'}"
ng-click="queryParams.status='20';listTopUpOrders(1)">fail</a> |
ng-click="queryParams.status='20';listTopUpOrders(1)">Fail</a> |
<a role="button" ng-class="{'bg-primary':queryParams.status=='99'}"
ng-click="queryParams.status='99';listTopUpOrders(1)">Error</a>
</p>
</div>
</div>
<div class="form-group col-xs-12">
<label class="control-label col-xs-4 col-sm-2">Type</label>
<div class="col-sm-10 col-xs-8">
<p class="form-control-static">
<a role="button" ng-class="{'bg-primary':queryParams.type==null}"
ng-click="queryParams.type='';listTopUpOrders(1)">All</a> |
<a role="button" ng-class="{'bg-primary':queryParams.type=='1'}"
ng-click="queryParams.type='1';listTopUpOrders(1)">Phone</a> |
<a role="button" ng-class="{'bg-primary':queryParams.type=='2'}"
ng-click="queryParams.type='2';listTopUpOrders(1)">Flow</a> |
<a role="button" ng-class="{'bg-primary':queryParams.type=='3'}"
ng-click="queryParams.type='3';listTopUpOrders(1)">QB</a>
</p>
</div>
</div>
<div class="form-group col-xs-12">
<label class="control-label col-xs-4 col-sm-2">Amount</label>
<div class="col-sm-10 col-xs-8">

@ -229,7 +229,7 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) {
app.controller('phonetopupCtrl', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {
$scope.topUp = function () {
var params = angular.copy($scope.params);
$http.get('/phone_top_up/recharge',{params: params}).then(function (resp) {
$http.get('/top_up/recharge',{params: params}).then(function (resp) {
alert('ok');
}, function (resp) {
alert(resp.data.message);

@ -0,0 +1,27 @@
package au.com.royalpay.payment.manage.ofei.core.impl;
import au.com.royalpay.payment.manage.ofei.core.OfeiClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* Created by wangning on 30/01/2018.
*/
@SpringBootTest
@ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
@RunWith(SpringRunner.class)
public class OfeiClientImplTest {
@Resource
private OfeiClient ofeiClient;
@Test
public void qbTopUp() throws Exception {
ofeiClient.qbTopUp("10","164851225");
}
}
Loading…
Cancel
Save