java微信分享(1)

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

后台

import com.ljzforum.base.enums.APIResponseCode;

import com.ljzforum.base.vo.APIResultVo;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**

  • @author : 恒果果

  • create at: 2019-12-09 10:48

  • @description: 微信分享等

*/

@RestController

public class WxController {

@Resource

private WXIConfig wxiConfig;

@RequestMapping(“/wxShare”)

public ModelAndView wxShare(String url){

ModelAndView view = new ModelAndView();

view.addObject(“data”,wxShareN(url))

return view ;

}

}

/**

  • 微信分享

*/

public LinkedHashMap<String,Object> wxShareN(String url) {

//微信分享

LinkedHashMap<String,Object> map = new LinkedHashMap<>();

try {

String ticket = wxService.getJssdkTicketN();

String shareUrl = url;

map.put(“appId”, wxiConfig.getAppId());

Map<String, String> signMap = WxJSSDKSign.sign(ticket, shareUrl);

map.put(“signMap”,signMap);

} catch (Exception e) {

log.error(“获取微信的JSSDK接口失败…”, e);

}

return map;

}

WXIConfig

import cn.hutool.http.HttpUtil;

import cn.hutool.json.JSONObject;

import cn.hutool.json.JSONUtil;

import com.ljzforum.common.constant.RedisContent;

import lombok.extern.slf4j.Slf4j;

import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.LinkedHashMap;

import java.util.Map;

import java.util.concurrent.TimeUnit;

/**

  • 微信接口的服务信息

  • @author

*/

@Service

@Slf4j

public class WxService {

@Resource

private RedisTemplate redisTemplate;

@Resource

private WXIConfig wxiConfig;

/**

  • 获取JSSDK的秘钥

*/

public String getJssdkTicket(String access_token) {

String ticket = (String) redisTemplate.opsForValue().get(RedisContent.WX_OPEN_TOKEN_TICKET + access_token);

if (ticket == null) {

Map<String, Object> params = new LinkedHashMap<String, Object>();

params.put(“access_token”, access_token);

params.put(“type”, “jsapi”);

JSONObject result = JSONUtil.parseObj(HttpUtil.get(WXIConfig.WX_JS_SDK_GET_TICKET, params));

if (result.containsKey(“errcode”) && !result.getStr(“errmsg”).equals(“ok”)) {

log.error(“获取ticket出错:” + result.toString());

return null;

}

ticket = result.getStr(“ticket”);

redisTemplate.opsForValue().set(RedisContent.WX_OPEN_TOKEN_TICKET + access_token, ticket, 30, TimeUnit.MINUTES);

}

return ticket;

}

/**

  • 获取JSSDK的秘钥

*/

public String getJssdkTicket() {

String access_token = getCgiBinTokenN();

if (access_token == null) {

return null;

}

String ticket;

try {

ticket = getJssdkTicket(access_token);

} catch (Exception e) {

log.error(“redisL里的的token不正确,重新从接口获取token”);

access_token = getCgiBinTokenN();

ticket = getJssdkTicket(access_token);

}

return ticket;

}

/**

  • 获取Token数据

*/

public String getCgiBinTokenN() {

String access_token = (String) redisTemplate.opsForValue().get(RedisContent.WX_CGI_BIN_TOKEN + wxiConfig.getAppId());

if (access_token == null) {

Map<String, Object> params = new LinkedHashMap<String, Object>();

params.put(“grant_type”, “client_credential”);

params.put(“appid”, wxiConfig.getAppId());

params.put(“secret”, wxiConfig.getAppSecret());

JSONObject result = JSONUtil.parseObj(HttpUtil.get(WXIConfig.WX_CGI_BIN_GET_TOKEN, params));

if (result.containsKey(“errcode”) && result.getStr(“errcode”) != null) {

result = JSONUtil.parseObj(HttpUtil.get(WXIConfig.WX_CGI_BIN_GET_TOKEN, params));

}

access_token = result.getStr(“access_token”);

redisTemplate.opsForValue().set(RedisContent.WX_CGI_BIN_TOKEN + wxiConfig.getAppId(), access_token, 30, TimeUnit.MINUTES);

}

return access_token;

}

}

WXIConfig

import com.ljzforum.common.util.CustomizedPropertyConfigurer;

import lombok.Data;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Component;

@Data

@Component

public class WXIConfig {

//微信支付分配的商户号

@Value(“${mch_id}”)

public String mchId;

//支付的私人秘钥

@Value(“${app_pay_key}”)

public String appPayKey;

//获取APPID

@Value(“${app_id}”)

public String appId;

//获取微信APP_SECRET

@Value(“${app_secret}”)

public String appSecret;

//获取小程序APPID

@Value(“${mini_appid}”)

public String miniAppid;

//获取小程序SECRET

@Value(“${mini_secret}”)

public String miniSecret;

//临时的整型参数值

public static String QR_SCENE = “QR_SCENE”;

//临时的字符串参数值

public static String QR_STR_SCENE = “QR_STR_SCENE”;

//永久的整型参数值

public static String QR_LIMIT_SCENE = “QR_LIMIT_SCENE”;

//永久的字符串参数值

public static String QR_LIMIT_STR_SCENE = “QR_LIMIT_STR_SCENE”;

//统一下单

public static String WX_UNIFIED_ORDER = “https://api.mch.weixin.qq.com/pay/unifiedorder”;

//获取access token

public static String WX_TOKEN = “https://api.weixin.qq.com/cgi-bin/token”;

//获取微信服务器IP地址

public static String WX_TOKEN_CALLBACK_IP = “https://api.weixin.qq.com/cgi-bin/getcallbackip”;

//用户同意授权,获取code

public static String WX_GET_USERINFO_AUTHORIZE = “https://open.weixin.qq.com/connect/oauth2/authorize”;

//通过code换取网页授权access_token

public static String WX_GET_USERINFO_ACCESS_TOKEN = “https://api.weixin.qq.com/sns/oauth2/access_token”;

//刷新access_token(如果需要)

public static String WX_GET_USERINFO_REFRESH_TOKEN = “https://api.weixin.qq.com/sns/oauth2/refresh_token”;

//刷新拉取用户信息(需scope为 snsapi_userinfo)

public static String WX_GET_USERINFO = “https://api.weixin.qq.com/sns/userinfo”;

//通过access_token、openid获取用户信息

public static String WX_GET_INFO = “https://api.weixin.qq.com/cgi-bin/user/info”;

//获取微信用户素材

public static String WX_BATCH_GET_MATERIAL = “https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=”;

//获取微信用户素材总数

public static String WX_GET_MATERIAL_COUNT = “https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=”;

//获取微信永久素材

public static String WX_GET_MATERIAL = “https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=”;

//创建微信菜单

public static String WX_CREATE_MENU = “https://api.weixin.qq.com/cgi-bin/menu/create?access_token=”;

//查询微信菜单

public static String WX_GET_MENU = “https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=”;

//删除微信菜单

public static String WX_DELETE_MENU = “https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=”;

//微信退款

public static String WX_REFUND_URL = “https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=”;

//获取access_toke

public static String WX_CGI_BIN_GET_TOKEN = “https://api.weixin.qq.com/cgi-bin/token”;

//长链接转短链接接口

public static String WX_GET_SHORT_URL = “https://api.weixin.qq.com/cgi-bin/shorturl?access_token=”;

//新增其他类型永久素材

public static String WX_MATERIAL_ADD_MATERIAL = “http://api.weixin.qq.com/cgi-bin/material/add_material?access_token=%1s&type=%2s”;

/**

  • 获取JSSDK调研说需要的钥匙

*/

public static String WX_JS_SDK_GET_TICKET = “https://api.weixin.qq.com/cgi-bin/ticket/getticket”;

//微信开放平台公众号消息加解密Key

public static String WX_PLATFORM_ENCODING_AES_KEY = (String) CustomizedPropertyConfigurer.getContextProperty(“wx_platform_encoding_aes_key”);

//微信开放平台公众号消息校验Token

public static String WX_PLATFORM_TOKEN = (String) CustomizedPropertyConfigurer.getContextProperty(“wx_platform_token”);

//微信开放平台APPID

public static String WX_PLATFORM_APP_ID = (String) CustomizedPropertyConfigurer.getContextProperty(“wx_platform_app_id”);

//微信开放平台AppSecret

public static String WX_PLATFORM_APP_SECRET = (String) CustomizedPropertyConfigurer.getContextProperty(“wx_platform_app_secret”);

//获取第三方平台component_access_token

public static String WX_GET_COMPONENT_ACCESS_TOKEN = “https://api.weixin.qq.com/cgi-bin/component/api_component_token”;

//获取预授权码pre_auth_code

public static String WX_GET_PRE_AUTH_CODE = “https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=”;

//获取公众号的接口调用凭据和授权信息

public static String WX_API_QUERY_AUTH = “https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=”;

public static String WX_API_REFRESH_TOKEN = “https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=”;

public static String WX_GET_AUTHORIZER_INFO = “https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=”;

/**

  • 微信通知信息推送模版

*/

//模版id

public static String WX_TEMPLATE_ID_SUCCESS_SIGNUP = “w64cYpbQWD65KR6cziKipXNnBowEOSheqc7uoKUTR70”;

public static String WX_TEMPLATE_ID_ACTIVITY_MESSAGE = “jVXOi_SxSpGA9t9dHCHA7Ss50a4Y8KPLFVnCas5EaIc”;

//发送模版信息

public static String WX_SEND_TEMPLATE = “https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=”;

//微信短链生成接口

public static String WX_SHORT_URL = “https://api.weixin.qq.com/cgi-bin/shorturl?access_token=”;

public static String USER_LIST_URL = “https://api.weixin.qq.com/cgi-bin/user/get?access_token=”;

//生成带参数的二维码

public static String WX_QRCODE_URL = “https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=”;

//通过ticket换取二维码

public static String WX_CGI_BIN_QRCODE = “https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=”;

//客服接口-发消息

public static String WX_SEND_MSG_CUSTOM = “https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=”;

最后

总而言之,面试官问来问去,问的那些Redis知识点也就这么多吧,复习的不够到位,知识点掌握不够熟练,所以面试才会卡壳。将这些Redis面试知识解析以及我整理的一些学习笔记分享出来给大家参考学习

还有更多学习笔记面试资料也分享如下:

都是“Redis惹的祸”,害我差点挂在美团三面,真是“虚惊一场”

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
gi-bin/user/get?access_token=";

//生成带参数的二维码

public static String WX_QRCODE_URL = “https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=”;

//通过ticket换取二维码

public static String WX_CGI_BIN_QRCODE = “https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=”;

//客服接口-发消息

public static String WX_SEND_MSG_CUSTOM = “https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=”;

最后

总而言之,面试官问来问去,问的那些Redis知识点也就这么多吧,复习的不够到位,知识点掌握不够熟练,所以面试才会卡壳。将这些Redis面试知识解析以及我整理的一些学习笔记分享出来给大家参考学习

还有更多学习笔记面试资料也分享如下:

[外链图片转存中…(img-pobN2jxh-1714687870842)]

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

  • 29
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值