puhanshu
2022-04-14 7bfa6a85ad6a6c537b0f7ddb9f6a8795c8e8c866
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/util/WxMaConfiguration.java
@@ -2,6 +2,10 @@
import javax.annotation.Resource;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.user.SysAppConfigVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.StringUtils;
import org.springframework.stereotype.Component;
import cn.binarywang.wx.miniapp.api.WxMaService;
@@ -22,12 +26,26 @@
    @Resource
    private WxMaProperties properties;
    public WxMaService getMaService() {
    @Resource
    private UserService userService;
    public WxMaService getMaService(String areaCode) {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        WxMaService wxMaService = new WxMaServiceImpl();
        if(StringUtils.isNotEmpty(areaCode)) {
            R<SysAppConfigVO> r = userService.selectByAreaCode(areaCode);
            if(R.isOk(r)) {
                SysAppConfigVO sysAppConfigVO = r.getData();
                config.setAppid(sysAppConfigVO.getAppId());
                config.setSecret(sysAppConfigVO.getSecret());
                config.setMsgDataFormat(properties.getMsgDataFormat());
                wxMaService.setWxMaConfig(config);
                return wxMaService;
            }
        }
        config.setAppid(properties.getAppid());
        config.setSecret(properties.getSecret());
        config.setMsgDataFormat(properties.getMsgDataFormat());
        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);
        return wxMaService;
    }