Permana
2018-02-28 706e6e750af5d702e2826a5944183614bee29041
wap charging
4 files modified
76 ■■■■■ changed files
unipin_charge_service/src/main/java/id/co/accessmobile/carrier/billling/unipin/chargingservice/job/ChargeWorker.java 16 ●●●● patch | view | raw | blame | history
unipin_charge_service/src/main/java/id/co/accessmobile/carrier/billling/unipin/chargingservice/model/RequestOneStepPaymentModel.java 2 ●●● patch | view | raw | blame | history
unipin_charge_service/src/main/java/id/co/accessmobile/carrier/billling/unipin/chargingservice/service/ClientWapChargingService.java 56 ●●●●● patch | view | raw | blame | history
unipin_charge_service/src/main/resources/application-dev.properties 2 ●●● patch | view | raw | blame | history
unipin_charge_service/src/main/java/id/co/accessmobile/carrier/billling/unipin/chargingservice/job/ChargeWorker.java
....@@ -63,6 +63,8 @@
6363
6464 protected Gson gson = new Gson();
6565
66
+ protected long sessionID;
67
+
6668 protected SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
6769
6870 @Async("chargeExecutor")
....@@ -134,13 +136,13 @@
134136 private int chargeUser(BillParams billParams) {
135137 String logTitle = "chargeUser/Msisdn[" + billParams.getMsisdn() + "], BillCd[" + billParams.getBillId() + "], TrxId[" + billParams.getLineTrxId() + "], ";
136138 int billResponse;
137
- log.info(this.whitelist+" "+billParams.getMsisdn().matches(this.whitelist)+" "+billParams.getMsisdn());
139
+ log.info(this.whitelist + " " + billParams.getMsisdn().matches(this.whitelist) + " " + billParams.getMsisdn());
138140 if (billParams.getMsisdn().matches(this.whitelist)) {
139141 RequestOneStepPaymentModel paymentModel = new RequestOneStepPaymentModel();
140142 paymentModel.setMSISDN(billParams.getMsisdn());
141143 paymentModel.setPrice(billParams.getPrice());
142
- paymentModel.setSessionID(this.simpleDateFormat.format(new Date()) + "0000000001" + System.currentTimeMillis() / 1000);
143
- paymentModel.setContentID(this.providerCode + this.contentType + "0000");
144
+ paymentModel.setSessionID(this.simpleDateFormat.format(new Date()) + this.generateSessionID() + System.currentTimeMillis() / 1000);
145
+ paymentModel.setContentID(this.providerCode + this.contentType + "-0000");
144146 ResponseOneStepPaymentModel responseOneStepPaymentModel = this.clientWapChargingService.requestCharging(paymentModel);
145147 if (responseOneStepPaymentModel.getResult() == 1) {
146148 billResponse = HutchBillResponse.SUCCESS;
....@@ -198,4 +200,12 @@
198200 queueNotiMapper.insert(notiRequest);
199201 }
200202
203
+ protected String generateSessionID() {
204
+ if (System.currentTimeMillis() / 1000 == sessionID) {
205
+ sessionID++;
206
+ } else {
207
+ sessionID = System.currentTimeMillis() / 1000;
208
+ }
209
+ return String.valueOf(sessionID);
210
+ }
201211 }
unipin_charge_service/src/main/java/id/co/accessmobile/carrier/billling/unipin/chargingservice/model/RequestOneStepPaymentModel.java
....@@ -17,5 +17,5 @@
1717 protected String SessionID;
1818 protected String MSISDN;
1919 protected String ContentID;
20
- protected long price;
20
+ protected long Price;
2121 }
unipin_charge_service/src/main/java/id/co/accessmobile/carrier/billling/unipin/chargingservice/service/ClientWapChargingService.java
....@@ -50,6 +50,8 @@
5050
5151 protected Calendar calendar = Calendar.getInstance();
5252
53
+ protected Object accessTokenGeneratedKey = new Object();
54
+
5355 static {
5456 Application.disableSslVerification();
5557 }
....@@ -57,28 +59,30 @@
5759 @Scheduled(fixedDelay = 10 * 1000)
5860 protected void scheduleRefreshToken() {
5961 if (System.currentTimeMillis() - this.nextRefreshToken < 10 * 1000) {
60
- this.logger.info("send refresh token");
61
- RestTemplate restTemplate = new RestTemplate();
62
- HttpHeaders headers = new HttpHeaders();
63
- headers.set("Authorization", "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + this.password).getBytes()));
64
- headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
65
- MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
66
- param.add("grant_type", "refresh_token");
67
- param.add("refresh_token",this.nextAccessTokenRefresh);
68
- HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(param, headers);
69
- ResponseEntity<String> response = restTemplate.postForEntity(this.ip + "/token/", request, String.class);
70
- System.out.println(response.getBody());
71
- if (response.getStatusCode() == HttpStatus.OK) {
72
- RefreshToken tokenResponse = this.gson.fromJson(response.getBody().trim(),RefreshToken.class);
73
- this.nextAccessTokenRefresh = tokenResponse.getRefresh_token();
74
- this.accessToken = tokenResponse.getAccess_token();
75
- Timestamp now = new Timestamp(System.currentTimeMillis());
76
- calendar.setTime(now);
77
- calendar.add(Calendar.SECOND, (int) tokenResponse.getExpires_in());
78
- this.nextRefreshToken = calendar.getTime().getTime();
79
- logger.info("next refresh token " + this.nextRefreshToken);
80
- } else {
81
- logger.info("failed to generate refreash token");
62
+ synchronized (this.accessTokenGeneratedKey) {
63
+ this.logger.info("send refresh token");
64
+ RestTemplate restTemplate = new RestTemplate();
65
+ HttpHeaders headers = new HttpHeaders();
66
+ headers.set("Authorization", "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + this.password).getBytes()));
67
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
68
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
69
+ param.add("grant_type", "refresh_token");
70
+ param.add("refresh_token", this.nextAccessTokenRefresh);
71
+ HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(param, headers);
72
+ ResponseEntity<String> response = restTemplate.postForEntity(this.ip + "/token/", request, String.class);
73
+ System.out.println(response.getBody());
74
+ if (response.getStatusCode() == HttpStatus.OK) {
75
+ RefreshToken tokenResponse = this.gson.fromJson(response.getBody().trim(), RefreshToken.class);
76
+ this.nextAccessTokenRefresh = tokenResponse.getRefresh_token();
77
+ this.accessToken = tokenResponse.getAccess_token();
78
+ Timestamp now = new Timestamp(System.currentTimeMillis());
79
+ calendar.setTime(now);
80
+ calendar.add(Calendar.SECOND, (int) tokenResponse.getExpires_in());
81
+ this.nextRefreshToken = calendar.getTime().getTime();
82
+ logger.info("next refresh token " + this.nextRefreshToken);
83
+ } else {
84
+ logger.info("failed to generate refreash token");
85
+ }
8286 }
8387 }
8488 }
....@@ -115,11 +119,13 @@
115119 try {
116120 RestTemplate restTemplate = new RestTemplate();
117121 HttpHeaders headers = new HttpHeaders();
118
- headers.set("Authorization", "Bearer " + this.accessToken);
122
+ synchronized (this.accessTokenGeneratedKey) {
123
+ headers.set("Authorization", "Bearer " + this.accessToken);
124
+ }
119125 headers.setContentType(MediaType.APPLICATION_JSON);
120
- HttpEntity<RequestOneStepPaymentModel> request = new HttpEntity<>(requestPayment, headers);
126
+ HttpEntity<String> request = new HttpEntity<>(this.gson.toJson(requestPayment), headers);
121127 ResponseEntity<String> response = restTemplate.postForEntity(this.ip + "/payment/", request, String.class);
122
- result = this.gson.fromJson(response.getBody().trim(),ResponseOneStepPaymentModel.class);
128
+ result = this.gson.fromJson(response.getBody().trim(), ResponseOneStepPaymentModel.class);
123129 } catch (Exception ex) {
124130 this.logger.error(ex.getMessage(), ex);
125131 } finally {
unipin_charge_service/src/main/resources/application-dev.properties
....@@ -22,7 +22,7 @@
2222 app.queue.executor.coresize=2
2323 app.queue.executor.maxsize=2
2424
25
-hutch.fc.requesturl=http://10.17.91.160:7002/PMTApplyTariffbyCash
25
+hutch.fc.requesturl=http://localhost:57002/PMTApplyTariffbyCash
2626 hutch.fc.appid=000000011221
2727
2828 bot.telegram.token=525607346:AAFTIWe92y8wS2zobmGpyR7ptmjgNbtcMFI