chejianzheng пре 4 месеци
родитељ
комит
9fc719c1b5

+ 0 - 3
portal-service-domain/src/main/java/com/hfln/portal/domain/customer/util/WxOfficeAccountClient.java

@@ -28,9 +28,6 @@ import java.util.Map;
 @Component
 public class WxOfficeAccountClient {
 
-    private static final String APPID = "wx9b479fa3c2af4f21";
-    private static final String SECRET = "426effb7b58f9ba7c5f6dd1062db0074";
-
     @NotBlank
     @Value("${lnxx.wechat.office.account.appId}")
     private String appId;

+ 34 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/config/WxMpConfig.java

@@ -0,0 +1,34 @@
+package com.hfln.portal.infrastructure.config;
+
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
+import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.validation.constraints.NotBlank;
+
+
+@Configuration
+public class WxMpConfig {
+
+    @NotBlank
+    @Value("${lnxx.wechat.office.account.appId}")
+    private String appId;
+
+    @NotBlank
+    @Value("${lnxx.wechat.office.account.secret}")
+    private String secret;
+
+    @Bean
+    public WxMpService wxMpService() {
+        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
+        config.setAppId(appId);
+        config.setSecret(secret);
+
+        WxMpService service = new WxMpServiceImpl();
+        service.setWxMpConfigStorage(config);
+        return service;
+    }
+}

+ 26 - 168
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/job/ScheduledTask.java

@@ -1,168 +1,26 @@
-//package com.hfln.portal.infrastructure.job;
-//
-//import com.alibaba.fastjson2.JSONObject;
-//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-//import com.fasterxml.jackson.databind.JsonNode;
-//import com.fasterxml.jackson.databind.ObjectMapper;
-//import com.google.common.collect.Lists;
-//import com.hfln.portal.infrastructure.po.DevTarget;
-//import com.hfln.portal.infrastructure.service.DevTargetService;
-//import lombok.extern.slf4j.Slf4j;
-//import org.apache.http.client.methods.CloseableHttpResponse;
-//import org.apache.http.client.methods.HttpGet;
-//import org.apache.http.client.utils.URIBuilder;
-//import org.apache.http.util.EntityUtils;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.stereotype.Component;
-//
-//import java.io.ByteArrayInputStream;
-//import java.security.cert.CertificateExpiredException;
-//import java.security.cert.CertificateFactory;
-//import java.security.cert.CertificateNotYetValidException;
-//import java.security.cert.X509Certificate;
-//import java.sql.Timestamp;
-//import java.time.LocalDateTime;
-//import java.util.ArrayList;
-//import java.util.Date;
-//import java.util.List;
-//
-//@Slf4j
-//@Component
-//public class ScheduledTask {
-//
-//    @Autowired
-//    private DevTargetService devTargetService;
-//
-//    @Scheduled(cron = "0 0 1 * * ?")
-//    public void runAtOneAM() {
-//
-//        devTargetService.remove(new LambdaQueryWrapper<DevTarget>().lt(DevTarget::getCreateTime, LocalDateTime.now().plusDays(-3)));
-//        log.info("定时删除devTarget数据");
-//    }
-//
-//    @Scheduled(cron = "0 0 */6 * * ?")
-//    public void updateWxpayCert() {
-//        if(Environment.wxHttpClient != null) {
-//            CloseableHttpResponse res = null;
-//            try {
-//                List<X509Certificate> certs = new ArrayList<X509Certificate>();
-//                List<WxpaycertVO> wxcerts = baseDAO.queryByCondition(WxpaycertVO.class, null, "effective_time desc");
-//                URIBuilder uriBuilder = new URIBuilder("https://api.mch.weixin.qq.com/v3/certificates");
-//                HttpGet httpGet = new HttpGet(uriBuilder.build());
-//                httpGet.addHeader("Accept", "application/json");
-//                res = Environment.wxHttpClient.execute(httpGet);
-//                String body = EntityUtils.toString(res.getEntity());
-//                res.close();
-//                ObjectMapper mapper = new ObjectMapper();
-//                JsonNode dataNode = mapper.readTree(body).get("data");
-//                if (dataNode != null) {
-//                    for (int i = 0, count = dataNode.size(); i < count; i++) {
-//                        String serial_no = dataNode.get(i).get("serial_no").textValue();
-//                        boolean match = false;
-//                        for (WxpaycertVO c : wxcerts) {
-//                            if (serial_no.equals(c.getSerial_no())) {
-//                                match = true;
-//                                break;
-//                            }
-//                        }
-//                        if (!match) {
-//                            AesUtil decryptor = new AesUtil(Constants.WXMCHKEYV3.getBytes("UTF-8"));
-//                            JsonNode encryptCertificateNode = dataNode.get(i).get("encrypt_certificate");
-//                            String cert = decryptor.decryptToString(
-//                                    encryptCertificateNode.get("associated_data").toString().replaceAll("\"", "")
-//                                            .getBytes("utf-8"),
-//                                    encryptCertificateNode.get("nonce").toString().replaceAll("\"", "").getBytes("utf-8"),
-//                                    encryptCertificateNode.get("ciphertext").toString().replaceAll("\"", ""));
-//
-//                            CertificateFactory cf = CertificateFactory.getInstance("X509");
-//                            X509Certificate x509Cert = (X509Certificate) cf
-//                                    .generateCertificate(new ByteArrayInputStream(cert.getBytes("utf-8")));
-//                            try {
-//                                x509Cert.checkValidity();
-//                            } catch (CertificateExpiredException | CertificateNotYetValidException e) {
-//                                continue;
-//                            }
-//                            certs.add(x509Cert);
-//
-//                            WxpaycertVO c = new WxpaycertVO();
-//                            c.setSerial_no(dataNode.get(i).get("serial_no").textValue());
-//                            Date effective_time = DateUtil.parse("yyyy-MM-dd'T'HH:mm:ssX",
-//                                    dataNode.get(i).get("effective_time").textValue());
-//                            c.setEffective_time(new Timestamp(effective_time.getTime()));
-//                            Date expire_time = DateUtil.parse("yyyy-MM-dd'T'HH:mm:ssX",
-//                                    dataNode.get(i).get("expire_time").textValue());
-//                            c.setExpire_time(new Timestamp(expire_time.getTime()));
-//                            c.setCerttext(cert);
-//                            baseDAO.insert(c);
-//                        }
-//                    }
-//
-//                }
-//                if (certs.size() > 0) {
-//                    Log.info("新增证书:"+certs.size());
-//                    // 证书有变动重新加载
-//                    for (WxpaycertVO c : wxcerts) {
-//                        CertificateFactory cf = CertificateFactory.getInstance("X509");
-//                        X509Certificate x509Cert = (X509Certificate) cf
-//                                .generateCertificate(new ByteArrayInputStream(c.getCerttext().getBytes("utf-8")));
-//                        try {
-//                            x509Cert.checkValidity();
-//                        } catch (CertificateExpiredException | CertificateNotYetValidException e) {
-//                            continue;
-//                        }
-//                        certs.add(x509Cert);
-//                    }
-//                    Environment.wxHttpClient = WechatPayHttpClientBuilder.create()
-//                            .withMerchant(Constants.WXMCHID, Constants.WXMCHAPICERTNUM, Environment.wxPrivateKey)
-//                            .withWechatPay(certs).build();
-//                }
-//            } catch (Exception e) {
-//                e.printStackTrace();
-//            }
-//        }
-//
-//    }
-//
-//    @Scheduled(cron = "0 0 */1 * * ?")
-//    public void updateWxgzh() {
-//        if(StringUtils.isNotBlank(Constants.WXGZHAPPID) && StringUtils.isNotBlank(Constants.WXGZHAPPSECRET)) {
-//            String res = HttpUtil.request("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
-//                    + Constants.WXGZHAPPID + "&secret=" + Constants.WXGZHAPPSECRET, null, false, null, null);
-//            if(StringUtils.isNotEmpty(res)) {
-//                Constants.WXGZHACCESS_TOKEN = (String) JSONObject.parseObject(res).get("access_token");
-//                Log.info("公众号更新ACCESS_TOKEN:" + Constants.WXGZHACCESS_TOKEN);
-//                String res_str = HttpUtil.request("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="
-//                        + Constants.WXGZHACCESS_TOKEN + "&type=jsapi", null, false, null, null);
-//                if(StringUtils.isNotEmpty(res_str)) {
-//                    Constants.WXGZHJS_TICKET = (String) JSONObject.parseObject(res_str).get("ticket");
-//                    Log.info("公众号更新JS_TICKET:" + Constants.WXGZHJS_TICKET);
-//                }
-//            }
-//        }
-//    }
-//
-//    @Scheduled(cron = "0 0 */1 * * ?")
-//    public void updateWxxcx() {
-//        if(StringUtils.isNotBlank(Constants.WXXCXAPPID) && StringUtils.isNotBlank(Constants.WXXCXAPPSECRET)) {
-//            String res = HttpUtil.request("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
-//                    + Constants.WXXCXAPPID + "&secret=" + Constants.WXXCXAPPSECRET, null, false, null, null);
-//            if(StringUtils.isNotEmpty(res)) {
-//                Constants.WXXCXACCESS_TOKEN = (String) JSONObject.parseObject(res).get("access_token");
-//                Log.info("小程序更新ACCESS_TOKEN:" + Constants.WXXCXACCESS_TOKEN);
-//            }
-//        }
-//    }
-//
-//    @Scheduled(cron = "0 */1 * * * ?")
-//    public void processSblx() {
-//        List<String> sqls = Lists.newArrayList();
-//        List<SbVO> sbs = baseDAO.queryByCondition(SbVO.class, " and lx is null and UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(sign_time)>120 ", null);
-//        for(SbVO v : sbs) {
-//            sqls.add("update tbl_sb set lx=1 where id='"+v.getId()+"' ");
-//        }
-//        if(sqls.size() > 0) {
-//            baseDAO.getJdbcTemplate().batchUpdate(sqls.toArray(new String[] {}));
-//        }
-//    }
-//}
+package com.hfln.portal.infrastructure.job;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.hfln.portal.infrastructure.po.DevTarget;
+import com.hfln.portal.infrastructure.service.DevTargetService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+@Slf4j
+@Component
+public class ScheduledTask {
+
+    @Autowired
+    private DevTargetService devTargetService;
+
+    @Scheduled(cron = "0 0 1 * * ?")
+    public void runAtOneAM() {
+
+        devTargetService.remove(new LambdaQueryWrapper<DevTarget>().lt(DevTarget::getCreateTime, LocalDateTime.now().plusDays(-3)));
+        log.info("定时删除devTarget数据");
+    }
+}