puhanshu
2022-04-14 7bfa6a85ad6a6c537b0f7ddb9f6a8795c8e8c866
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.panzhihua.service_community.util;
 
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;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import lombok.extern.slf4j.Slf4j;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: wexin
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-11-23 15:07
 **/
@Slf4j
@Component
public class WxMaConfiguration {
 
    @Resource
    private WxMaProperties properties;
 
    @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.setWxMaConfig(config);
        return wxMaService;
    }
}