feat: 新功能开发,监测历史记录。微信和物联网平台,模块搭建。
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.intc.weixin.service;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
/**
|
||||
* 微信小程序服务接口
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
public interface WxMaService {
|
||||
|
||||
/**
|
||||
* 登录凭证校验
|
||||
*
|
||||
* @param code 登录时获取的 code
|
||||
* @return sessionKey和openId
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
String code2Session(String code) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取小程序码
|
||||
*
|
||||
* @param scene 场景值
|
||||
* @param page 页面路径
|
||||
* @return 二进制图片数据
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
byte[] getUnlimitedQrCode(String scene, String page) throws WxErrorException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.intc.weixin.service;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
|
||||
/**
|
||||
* 微信公众号服务接口
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
public interface WxMpService {
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param openId 用户openId
|
||||
* @return 用户信息
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
WxMpUser getUserInfo(String openId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 生成二维码ticket
|
||||
*
|
||||
* @param sceneStr 场景值
|
||||
* @return ticket
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
String createQrCode(String sceneStr) throws WxErrorException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.intc.weixin.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import com.intc.weixin.service.WxMaService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 微信小程序服务实现
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(cn.binarywang.wx.miniapp.api.WxMaService.class)
|
||||
public class WxMaServiceImpl implements WxMaService {
|
||||
|
||||
private final cn.binarywang.wx.miniapp.api.WxMaService wxMaService;
|
||||
|
||||
@Override
|
||||
public String code2Session(String code) throws WxErrorException {
|
||||
log.info("小程序登录, code: {}", code);
|
||||
WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(code);
|
||||
return session.getOpenid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getUnlimitedQrCode(String scene, String page) throws WxErrorException {
|
||||
log.info("生成小程序码, scene: {}, page: {}", scene, page);
|
||||
return wxMaService.getQrcodeService().createWxaCodeUnlimitBytes(scene, page, false, null, 430, true, null, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.intc.weixin.service.impl;
|
||||
|
||||
import com.intc.weixin.service.WxMpService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 微信公众号服务实现
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(me.chanjar.weixin.mp.api.WxMpService.class)
|
||||
public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
private final me.chanjar.weixin.mp.api.WxMpService wxMpService;
|
||||
|
||||
@Override
|
||||
public WxMpUser getUserInfo(String openId) throws WxErrorException {
|
||||
log.info("获取微信用户信息, openId: {}", openId);
|
||||
return wxMpService.getUserService().userInfo(openId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createQrCode(String sceneStr) throws WxErrorException {
|
||||
log.info("创建微信二维码, sceneStr: {}", sceneStr);
|
||||
WxMpQrCodeTicket ticket = wxMpService.getQrcodeService()
|
||||
.qrCodeCreateTmpTicket(sceneStr, 2592000);
|
||||
return ticket.getUrl();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user