Blame view

WechatUtil.java 2.07 KB
涂亚平 committed
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
package com.meishu.util;

import com.alibaba.fastjson.JSONObject;
import com.meishu.common.constant.WxConstant;
import com.meishu.vo.wechat.AccessTokenVO;
import com.meishu.vo.wechat.MemberVO;
import com.meishu.vo.wechat.QrConnectVO;
import com.meishu.vo.wechat.WXUserInfoVO;

import java.util.HashMap;
import java.util.Map;

public class WechatUtil {

    /**
     * Access Token
     * @return
     */
    public static AccessTokenVO getAccessToken() {
        Map<String, Object> param = new HashMap<>();
        param.put("appid", WxConstant.APPID);
        param.put("secret", WxConstant.SECRENT);
        JSONObject object = HttpUtil.get(param, WxConstant.GET_SUITE_TOKEN);
        return JSONObject.toJavaObject(object, AccessTokenVO.class);
    }

    /**
     * 获取访问用户身份
     * @param accessToken
     * @param code
     * @return
     */
    public static WXUserInfoVO getUserInfo(String accessToken, String code) {
        Map<String, Object> param = new HashMap<>();
        param.put("access_token", accessToken);
        param.put("code", code);
        JSONObject object = HttpUtil.get(param, WxConstant.GETUSERINFO);
        return JSONObject.toJavaObject(object, WXUserInfoVO.class);
    }

    /**
     * 读取成员
     * @param accessToken
     * @param userId
     * @return
     */
    public static MemberVO getMember(String accessToken, String userId) {
        Map<String, Object> param = new HashMap<>();
        param.put("access_token", accessToken);
        param.put("userid", userId);
        JSONObject object = HttpUtil.get(param, WxConstant.GET);
        return JSONObject.toJavaObject(object, MemberVO.class);
    }

    /**
     * 扫码登陆参数
     * @return
     */
    public static QrConnectVO getQRConnectParams() {
        QrConnectVO qrConnectVO = new QrConnectVO();
        qrConnectVO.setId("双创系统");
        qrConnectVO.setAppId(WxConstant.APPID);
//        qrConnectVO.setAgentId(WxConstant.AGENTID);
        qrConnectVO.setRedirectUri(WxConstant.QR_REDIRECT_URL);
        qrConnectVO.setState("MASS");
        return qrConnectVO;
    }
}