Jelajahi Sumber

完善对接企业微信-获取收款记录接口

cgp 1 bulan lalu
induk
melakukan
ff2ca00e33

+ 3 - 2
fs-company/src/main/java/com/fs/company/controller/qw/FsCompanyExternalPayReceiptController.java

@@ -19,8 +19,9 @@ public class FsCompanyExternalPayReceiptController extends BaseController {
     @GetMapping("/sync")
     public AjaxResult sync(@RequestParam Long beginTime,
                            @RequestParam Long endTime,
-                           @RequestParam(required = false) String payeeUserid) {
-        receiptService.syncReceipts(beginTime, endTime, payeeUserid);
+                           @RequestParam(required = false) String payeeUserid,
+                           @RequestParam String corpId) {
+        receiptService.syncReceipts(beginTime, endTime, payeeUserid,corpId);
         return AjaxResult.success("同步完成");
     }
 }

+ 1 - 1
fs-service/src/main/java/com/fs/qw/service/IFsCompanyExternalPayReceiptService.java

@@ -7,7 +7,7 @@ import java.util.List;
 public interface IFsCompanyExternalPayReceiptService {
 
     // 同步收款记录(定时任务同步或手动同步)
-    void syncReceipts(Long beginTime, Long endTime, String payeeUserid);
+    void syncReceipts(Long beginTime, Long endTime, String payeeUserid,String corpId);
 
     // 查询收款记录(查数据库)
     List<FsCompanyExternalPayReceipt> queryReceipts(FsCompanyExternalPayReceipt receipt);

+ 2 - 2
fs-service/src/main/java/com/fs/qw/service/impl/FsCompanyExternalPayReceiptServiceImpl.java

@@ -28,8 +28,8 @@ public class FsCompanyExternalPayReceiptServiceImpl implements IFsCompanyExterna
     // 同步收款记录(定时任务同步或手动同步)
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void syncReceipts(Long beginTime, Long endTime, String payeeUserid) {
-        List<ReceiptDto> receiptList = weWorkPayService.fetchAllReceipts(beginTime, endTime, payeeUserid);
+    public void syncReceipts(Long beginTime, Long endTime, String payeeUserid,String corpId) {
+        List<ReceiptDto> receiptList = weWorkPayService.fetchAllReceipts(beginTime, endTime, payeeUserid,corpId);
         if (CollectionUtils.isEmpty(receiptList)) {
             log.info("没有需要同步的收款记录");
             return;

+ 11 - 20
fs-service/src/main/java/com/fs/qw/service/impl/WeWorkExternalPayService.java

@@ -4,9 +4,10 @@ import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.fs.qw.domain.QwCompany;
 import com.fs.qw.dto.ReceiptDto;
-import com.fs.wx.kf.service.IWeixinKfService;
-import com.fs.wx.kf.vo.WeixinKfTokenVO;
+import com.fs.qw.service.IQwCompanyService;
+import com.fs.qwApi.service.QwApiService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -26,24 +27,11 @@ import java.util.Map;
 public class WeWorkExternalPayService {
 
     @Autowired
-    private IWeixinKfService weixinKfService;
+    private QwApiService qwApiService;
 
-    @Value("123")
-    private String corpId;
+    @Autowired
+    private IQwCompanyService iQwCompanyService;
 
-    @Value("123")
-    private String corpSecret;
-
-    /**
-     * 获取 access_token
-     */
-    private String getAccessToken() {
-        WeixinKfTokenVO tokenVO = weixinKfService.getToken(corpId, corpSecret);
-        if (tokenVO.getErrcode() != null && tokenVO.getErrcode() != 0) {
-            throw new RuntimeException("获取企业微信access_token失败:" + tokenVO.getErrmsg());
-        }
-        return tokenVO.getAccess_token();
-    }
 
     /**
      * 拉取所有收款记录(自动分页)
@@ -51,7 +39,10 @@ public class WeWorkExternalPayService {
      * @param endTime   结束时间戳(秒)
      * @param payeeUserid 可选,收款成员userid
      */
-    public List<ReceiptDto> fetchAllReceipts(Long beginTime, Long endTime, String payeeUserid) {
+    public List<ReceiptDto> fetchAllReceipts(Long beginTime, Long endTime, String payeeUserid,String corpId) {
+        QwCompany qwCompany = iQwCompanyService.selectQwCompanyByCorpId(corpId);
+        String openSecret = qwCompany.getOpenSecret();
+
         List<ReceiptDto> allReceipts = new ArrayList<>();
         String cursor = null;
 
@@ -67,7 +58,7 @@ public class WeWorkExternalPayService {
             }
             params.put("limit", 1000);
 
-            String accessToken = getAccessToken();
+            String accessToken = qwApiService.getToken(corpId, openSecret);
             String url = "https://qyapi.weixin.qq.com/cgi-bin/externalpay/get_bill_list?access_token=" + accessToken;
 
             // 发送 POST 请求