|
|
@@ -1,5 +1,6 @@
|
|
|
package org.springblade.yeePay.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.yeepay.yop.sdk.exception.YopClientException;
|
|
|
import com.yeepay.yop.sdk.service.common.YopClient;
|
|
|
import com.yeepay.yop.sdk.service.common.YopClientBuilder;
|
|
|
@@ -8,12 +9,12 @@ import com.yeepay.yop.sdk.service.common.response.YopResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springblade.wx.config.WXConfiger;
|
|
|
import org.springblade.yeePay.common.YeePayConst;
|
|
|
+import org.springblade.yeePay.entity.ConfigAppDto;
|
|
|
import org.springblade.yeePay.entity.InitOrderDto;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@@ -26,25 +27,20 @@ public class YeePayService {
|
|
|
|
|
|
/**
|
|
|
* 易宝 公众号配置
|
|
|
- **/
|
|
|
- public void configApp() {
|
|
|
+ * @param appIdList
|
|
|
+ * @return*/
|
|
|
+ public boolean configApp(ConfigAppDto[] appIdList) {
|
|
|
YopRequest request = new YopRequest("/rest/v2.0/aggpay/wechat-config/add", "POST");
|
|
|
- request.addParameter("parentMerchantNo","APPIDapp_10086062555");
|
|
|
- request.addParameter("merchantNo","APPIDapp_10086062555");
|
|
|
- request.addParameter("appIdList","[\n" +
|
|
|
- " {\n" +
|
|
|
- " \"appId\":\""+wxConfiger.getAppId()+"\",\n" +
|
|
|
- " \"appSecret\":\"appSecret\",\n" +
|
|
|
- " \"appIdType\":\"OFFICIAL_ACCOUNT\",\n" +
|
|
|
- " \"subscribeAppId\":\"subscribeAppId\"\n" +
|
|
|
- " }\n" +
|
|
|
- "]");
|
|
|
+ request.addParameter("parentMerchantNo",yeePayConst.getParentMerchantNo());
|
|
|
+ request.addParameter("merchantNo",yeePayConst.getMerchantNo());
|
|
|
+ request.addParameter("appIdList", JSON.toJSONString(appIdList));
|
|
|
try {
|
|
|
YopResponse response = yopClient.request(request);
|
|
|
System.out.println(response);
|
|
|
} catch (YopClientException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -56,11 +52,28 @@ public class YeePayService {
|
|
|
YopRequest request = new YopRequest("/rest/v1.0/aggpay/pre-pay", "POST");
|
|
|
request.addParameter("parentMerchantNo",yeePayConst.getParentMerchantNo());
|
|
|
request.addParameter("merchantNo",yeePayConst.getMerchantNo());
|
|
|
+ addParamsFromObj(initOrderDto,request);
|
|
|
+ YopResponse response = null;
|
|
|
+ try {
|
|
|
+ response = yopClient.request(request);
|
|
|
+ } catch (YopClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加请求参数
|
|
|
+ * @param obj 请求所需DTO对象
|
|
|
+ * @param request 所需添加参数请求
|
|
|
+ * */
|
|
|
+ private void addParamsFromObj(Object obj,YopRequest request){
|
|
|
Arrays.stream(InitOrderDto.class.getDeclaredFields())
|
|
|
.forEach(field -> {
|
|
|
field.setAccessible(true);
|
|
|
try {
|
|
|
- String paramValue = field.get(initOrderDto).toString();
|
|
|
+ String paramValue = field.get(obj).toString();
|
|
|
if(paramValue!=null&!"".equals(paramValue)){
|
|
|
request.addParameter(field.getName(),paramValue);
|
|
|
}
|
|
|
@@ -69,16 +82,7 @@ public class YeePayService {
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
- YopResponse response = null;
|
|
|
- try {
|
|
|
- response = yopClient.request(request);
|
|
|
- } catch (YopClientException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return false;
|
|
|
}
|
|
|
public static void main(String[] args) {
|
|
|
- YeePayService yeePayService = new YeePayService();
|
|
|
- yeePayService.configApp();
|
|
|
}
|
|
|
}
|