|
|
@@ -26,25 +26,34 @@ import com.ruoyi.web.pcApi.domain.TOrderManageTotal;
|
|
|
import com.ruoyi.web.pcApi.service.ITOrderManageService;
|
|
|
|
|
|
@Component
|
|
|
-public class LinePay implements Serializable {
|
|
|
+public class LinePay implements Serializable {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
/** log */
|
|
|
private static final Logger log = LoggerFactory.getLogger(LinePay.class);
|
|
|
|
|
|
- @Autowired
|
|
|
- private LineConfig lineConfig;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ITOrderManageService orderManageService;
|
|
|
+ @Autowired
|
|
|
+ private LineConfigFactory lineConfigFactory;
|
|
|
|
|
|
+ /**
|
|
|
+ * 通过busId取得bus公司信息。
|
|
|
+ *
|
|
|
+ * @param deptId バスID
|
|
|
+ */
|
|
|
+ public LineConfig getConfig(long deptId) {
|
|
|
+ return lineConfigFactory.getLineConfig(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* create the line pay request body.
|
|
|
- *
|
|
|
+ * @param deptId バスID
|
|
|
* @param orderManageTotal 订单管理-总对象
|
|
|
* @return line pay request body
|
|
|
*/
|
|
|
- public SendBody createSendBody(TOrderManageTotal orderManageTotal, String deptName) {
|
|
|
+ public SendBody createSendBody(long deptId, TOrderManageTotal orderManageTotal, String deptName) {
|
|
|
+ LineConfig lineConfig = getConfig(deptId);
|
|
|
//create line pay request body
|
|
|
SendBody sendBody = new SendBody();
|
|
|
|
|
|
@@ -93,9 +102,9 @@ public class LinePay implements Serializable {
|
|
|
//call back urls
|
|
|
RedirectUrls callBack = new RedirectUrls();
|
|
|
//confirm url
|
|
|
- callBack.setConfirmUrl(lineConfig.callbankConfirmUrl);
|
|
|
+ callBack.setConfirmUrl(lineConfig.getCallbankConfirmUrl());
|
|
|
//cancel url
|
|
|
- callBack.setCancelUrl(lineConfig.callbankCancelUrl);
|
|
|
+ callBack.setCancelUrl(lineConfig.getCallbankCancelUrl());
|
|
|
|
|
|
sendBody.setRedirectUrls(callBack);
|
|
|
|
|
|
@@ -104,10 +113,11 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
/**
|
|
|
* set the header info
|
|
|
+ *
|
|
|
* @param request
|
|
|
* @throws URISyntaxException
|
|
|
*/
|
|
|
- private void setHeaderAndEntity(HttpPost request, String sendBody) throws URISyntaxException {
|
|
|
+ private void setHeaderAndEntity(HttpPost request, String sendBody, LineConfig lineConfig) throws URISyntaxException {
|
|
|
String nonce = UUID.randomUUID().toString();
|
|
|
request.setHeader("Content-Type", "application/json");
|
|
|
request.setHeader("X-LINE-ChannelId", lineConfig.channelId);
|
|
|
@@ -134,12 +144,14 @@ public class LinePay implements Serializable {
|
|
|
}
|
|
|
/**
|
|
|
* line pay
|
|
|
+ *
|
|
|
+ * @param deptId バスID
|
|
|
* @param orderManageTotal
|
|
|
*/
|
|
|
- public LinePayAPOD pay(TOrderManageTotal orderManageTotal, String deptName) {
|
|
|
-
|
|
|
+ public LinePayAPOD pay(long deptId, TOrderManageTotal orderManageTotal, String deptName) {
|
|
|
+ LineConfig lineConfig = getConfig(deptId);
|
|
|
//create request body
|
|
|
- SendBody sendBody = createSendBody(orderManageTotal, deptName);
|
|
|
+ SendBody sendBody = createSendBody(deptId, orderManageTotal, deptName);
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
@@ -153,7 +165,7 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
log.info(sendBodyStr);
|
|
|
|
|
|
- setHeaderAndEntity(request, sendBodyStr);
|
|
|
+ setHeaderAndEntity(request, sendBodyStr, lineConfig);
|
|
|
|
|
|
response = client.execute(request, httpResponse ->
|
|
|
mapper.readValue(EntityUtils.toString(httpResponse.getEntity()), LinePayAPOD.class));
|
|
|
@@ -170,10 +182,13 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
/**
|
|
|
* confirm line pay
|
|
|
+ *
|
|
|
+ * @param deptId バスID
|
|
|
* @param transactionId
|
|
|
* @param total
|
|
|
*/
|
|
|
- public LinePayConfirmAPOD payConfirm(String transactionId, long total) {
|
|
|
+ public LinePayConfirmAPOD payConfirm(long deptId, String transactionId, long total) {
|
|
|
+ LineConfig lineConfig = getConfig(deptId);
|
|
|
//
|
|
|
ConfirmBody body = new ConfirmBody();
|
|
|
|
|
|
@@ -191,7 +206,7 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
HttpPost request = new HttpPost(formatStr);
|
|
|
|
|
|
- setHeaderAndEntity(request, mapper.writeValueAsString(body));
|
|
|
+ setHeaderAndEntity(request, mapper.writeValueAsString(body), lineConfig);
|
|
|
|
|
|
response = client.execute(request, httpResponse ->
|
|
|
mapper.readValue(EntityUtils.toString(httpResponse.getEntity()), LinePayConfirmAPOD.class));
|
|
|
@@ -208,10 +223,14 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
/**
|
|
|
* 決済完了(売上確定済み)された取引を返金します。
|
|
|
+ * @param deptId バスID
|
|
|
* @param transactionId
|
|
|
* @param refundAmount
|
|
|
*/
|
|
|
- public LinePayRefundAPOD payRefund(String transactionId, Long refundAmount) {
|
|
|
+ public LinePayRefundAPOD payRefund(long deptId, String transactionId, Long refundAmount) {
|
|
|
+
|
|
|
+ LineConfig lineConfig = getConfig(deptId);
|
|
|
+
|
|
|
//
|
|
|
RefundBody body = new RefundBody();
|
|
|
|
|
|
@@ -229,7 +248,7 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
HttpPost request = new HttpPost(formatStr);
|
|
|
|
|
|
- setHeaderAndEntity(request, mapper.writeValueAsString(body));
|
|
|
+ setHeaderAndEntity(request, mapper.writeValueAsString(body), lineConfig);
|
|
|
|
|
|
response = client.execute(request, httpResponse ->
|
|
|
mapper.readValue(EntityUtils.toString(httpResponse.getEntity()), LinePayRefundAPOD.class));
|
|
|
@@ -243,4 +262,31 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
return response;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public void pushMessage(long deptId, PushMessage msg) {
|
|
|
+ LineConfig lineConfig = getConfig(deptId);
|
|
|
+
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+
|
|
|
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
+
|
|
|
+ HttpPost request = new HttpPost(lineConfig.pullMsgUrl);
|
|
|
+
|
|
|
+ request.setHeader("Content-Type", "application/json");
|
|
|
+ request.setHeader("Authorization", "Bearer " + lineConfig.botChannelToken);
|
|
|
+
|
|
|
+ request.setEntity(new StringEntity(mapper.writeValueAsString(msg), ContentType.APPLICATION_JSON));
|
|
|
+
|
|
|
+ client.execute(request, httpResponse ->
|
|
|
+ mapper.readValue(EntityUtils.toString(httpResponse.getEntity()), Object.class));
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+
|
|
|
+ log.error("line message API エラーが発生しました。", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|