|
@@ -2,7 +2,12 @@ package com.ym.mec.web.controller.payment;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
@@ -15,15 +20,25 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.beust.jcommander.internal.Maps;
|
|
|
+import com.yeepay.yop.sdk.http.YopContentType;
|
|
|
+import com.yeepay.yop.sdk.service.common.YopCallbackEngine;
|
|
|
+import com.yeepay.yop.sdk.service.common.callback.YopCallback;
|
|
|
+import com.yeepay.yop.sdk.service.common.callback.YopCallbackRequest;
|
|
|
import com.yeepay.yop.sdk.service.mer.response.RegisterQueryV2Response;
|
|
|
import com.ym.mec.biz.dal.dto.YeepayMember;
|
|
|
import com.ym.mec.biz.dal.entity.HfMember;
|
|
|
import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
|
|
|
import com.ym.mec.biz.dal.page.HfMemberQueryInfo;
|
|
|
import com.ym.mec.biz.service.HfMemberService;
|
|
|
+import com.ym.mec.biz.service.HfMerchantConfigService;
|
|
|
import com.ym.mec.common.controller.BaseController;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
+import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
+import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
+import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
|
|
|
import com.ym.mec.thirdparty.yeepay.YeepayMerchantService;
|
|
|
import com.ym.mec.thirdparty.yeepay.YeepayUploadService;
|
|
|
import com.ym.mec.thirdparty.yeepay.entity.MerchantInfo;
|
|
@@ -40,6 +55,9 @@ public class YeepayController extends BaseController {
|
|
|
private HfMemberService hfMemberService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private HfMerchantConfigService hfMerchantConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private YeepayUploadService yeepayUploadService;
|
|
|
|
|
|
@Autowired
|
|
@@ -69,9 +87,11 @@ public class YeepayController extends BaseController {
|
|
|
@PostMapping(value = "addSubMerchant")
|
|
|
@PreAuthorize("@pcs.hasPermissions('yeepay/addSubMerchant')")
|
|
|
public HttpResponseResult<Boolean> addSubMerchant(YeepayMember member) throws Exception {
|
|
|
- if (!profiles.equals("prod")) {
|
|
|
- return failed("仅生产环境可用");
|
|
|
- }
|
|
|
+ /*
|
|
|
+ * if (!profiles.equals("prod")) { return failed("仅生产环境可用"); }
|
|
|
+ */
|
|
|
+
|
|
|
+ member.setPayerName(PaymentChannelEnum.YEEPAY.getCode());
|
|
|
|
|
|
return succeed(hfMemberService.createMember(member, null));
|
|
|
}
|
|
@@ -84,6 +104,42 @@ public class YeepayController extends BaseController {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/callback")
|
|
|
+ public String callback(HttpServletRequest request) {
|
|
|
+
|
|
|
+ String callbackUrl = "/yeepay/callback";
|
|
|
+ // 这个是您收到的header,为了方便测试,下面提供了示例数据
|
|
|
+ Map<String, String> headers = Maps.newHashMap();
|
|
|
+ headers.put("Authorization", request.getHeader("Authorization"));
|
|
|
+ headers.put("x-yop-content-sm3", request.getHeader("x-yop-content-sm3"));
|
|
|
+ headers.put("x-yop-encrypt", request.getHeader("x-yop-encrypt"));
|
|
|
+ headers.put("x-yop-request-id", request.getHeader("x-yop-request-id"));
|
|
|
+ headers.put("x-yop-sign-serial-no", request.getHeader("x-yop-sign-serial-no"));
|
|
|
+ headers.put("x-yop-appkey", request.getHeader("x-yop-appkey"));
|
|
|
+ headers.put("Content-Type", request.getHeader("Content-Type"));
|
|
|
+
|
|
|
+ String content;
|
|
|
+ try {
|
|
|
+ content = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
|
|
+ // 构造结果通知请求对象
|
|
|
+ YopCallbackRequest yopCallbackRequest =
|
|
|
+ new YopCallbackRequest(callbackUrl, "POST")
|
|
|
+ .setContentType(YopContentType.JSON)
|
|
|
+ .setHeaders(headers)
|
|
|
+ .setContent(content);
|
|
|
+
|
|
|
+ YopCallback callback = YopCallbackEngine.parse(yopCallbackRequest);
|
|
|
+
|
|
|
+ System.out.println("开户回调信息:" + JSON.toJSONString(callback));
|
|
|
+
|
|
|
+ return "SUCCESS";
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation("修改企业用户(状态是failed才能修改)")
|
|
|
@PostMapping(value = "upload")
|
|
|
@PreAuthorize("@pcs.hasPermissions('yeepay/upload')")
|
|
@@ -99,8 +155,13 @@ public class YeepayController extends BaseController {
|
|
|
}
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
IOUtils.copy(inputStream, fos);
|
|
|
+
|
|
|
+ HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(TenantContextHolder.getTenantId(), PaymentChannelEnum.YEEPAY.getCode());
|
|
|
+ if(hfMerchantConfig == null){
|
|
|
+ throw new BizException("请配置机构的汇付商户信息");
|
|
|
+ }
|
|
|
|
|
|
- return succeed(yeepayUploadService.upload(file));
|
|
|
+ return succeed(yeepayUploadService.upload(hfMerchantConfig.getAppId(), file));
|
|
|
} catch (Exception e) {
|
|
|
return failed(e.getMessage());
|
|
|
} finally {
|