dev-discount
parent
497a7a30af
commit
2d8fdf4ee2
@ -0,0 +1,121 @@ |
||||
package com.v1.config; |
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import me.chanjar.weixin.common.error.WxErrorException; |
||||
import me.chanjar.weixin.mp.api.WxMpService; |
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* @serviceName WeChatQrcodeUtils.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // 生成带参数的二维码
|
||||
* @createTime 16:11 2022/9/2 |
||||
**/ |
||||
@Slf4j |
||||
@Component |
||||
public class WeChatQrcodeUtils { |
||||
|
||||
@Autowired |
||||
private WxMpService wxMpService; |
||||
|
||||
/** |
||||
* <pre> |
||||
* 创建临时二维码ticket |
||||
* @param sceneId 场景值ID,临时二维码时为32位非0整型 |
||||
* @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 |
||||
* @auther: cao_wencao |
||||
* @date: 2019/2/18 16:58 |
||||
* </pre> |
||||
*/ |
||||
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException { |
||||
WxMpQrCodeTicket wxMpQrCodeTicket = wxMpService.getQrcodeService().qrCodeCreateTmpTicket(sceneId, expireSeconds); |
||||
return wxMpQrCodeTicket; |
||||
} |
||||
|
||||
/** |
||||
* <pre> |
||||
* 创建临时二维码ticket |
||||
* @param sceneStr 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64 |
||||
* @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 |
||||
* @auther: cao_wencao |
||||
* @date: 2019/2/18 17:01 |
||||
* </pre> |
||||
*/ |
||||
public WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException { |
||||
WxMpQrCodeTicket wxMpQrCodeTicket = wxMpService.getQrcodeService().qrCodeCreateTmpTicket(sceneStr, expireSeconds); |
||||
return wxMpQrCodeTicket; |
||||
} |
||||
|
||||
/** |
||||
* <pre> |
||||
* 创建永久二维码ticket |
||||
* @param sceneId 场景值ID,最大值为100000(目前参数只支持1--100000) |
||||
* @auther: cao_wencao |
||||
* @date: 2019/2/18 17:03 |
||||
* </pre> |
||||
*/ |
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException { |
||||
return wxMpService.getQrcodeService().qrCodeCreateLastTicket(sceneId); |
||||
} |
||||
|
||||
/** |
||||
* <pre> |
||||
* 创建永久字符串二维码ticket |
||||
* @param sceneStr 参数。字符串类型长度现在为1到64 |
||||
* @auther: cao_wencao |
||||
* @date: 2019/2/18 17:05 |
||||
* </pre> |
||||
*/ |
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException { |
||||
return wxMpService.getQrcodeService().qrCodeCreateLastTicket(sceneStr); |
||||
} |
||||
|
||||
/** |
||||
* <pre> |
||||
* 换取二维码图片文件,jpg格式 |
||||
* @param ticket 二维码ticket |
||||
* @auther: cao_wencao |
||||
* @date: 2019/2/18 17:07 |
||||
* </pre> |
||||
*/ |
||||
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException { |
||||
return wxMpService.getQrcodeService().qrCodePicture(ticket); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* <pre> |
||||
* 换取二维码图片url地址(可以选择是否生成压缩的网址) |
||||
* @param ticket 二维码ticket |
||||
* @param needShortUrl 是否需要压缩的二维码地址 |
||||
* @auther: cao_wencao |
||||
* @date: 2019/2/18 17:10 |
||||
* </pre> |
||||
*/ |
||||
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException { |
||||
String qrCodeUrl = wxMpService.getQrcodeService().qrCodePictureUrl(ticket, needShortUrl); |
||||
return qrCodeUrl; |
||||
} |
||||
|
||||
/** |
||||
* <pre> |
||||
* 换取二维码图片url地址 |
||||
* @param ticket 二维码ticket |
||||
* @auther: cao_wencao |
||||
* @date: 2019/2/18 17:11 |
||||
* </pre> |
||||
*/ |
||||
public String qrCodePictureUrl(String ticket) throws WxErrorException { |
||||
String url = wxMpService.getQrcodeService().qrCodePictureUrl(ticket); |
||||
return url; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,51 @@ |
||||
package com.v1.config; |
||||
|
||||
import com.hai.config.CommonSysConst; |
||||
import me.chanjar.weixin.mp.api.WxMpService; |
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; |
||||
import me.chanjar.weixin.mp.config.WxMpConfigStorage; |
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
/** |
||||
* @serviceName .java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description //TODO
|
||||
* @createTime 16:24 2022/9/2 |
||||
**/ |
||||
@Configuration |
||||
public class WxConfig { |
||||
|
||||
|
||||
/** |
||||
* 微信客户端配置存储 |
||||
* |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public WxMpConfigStorage wxMpConfigStorage() { |
||||
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl(); |
||||
// 公众号appId
|
||||
configStorage.setAppId(SysConst.getSysConfig().getWxH5AppId()); |
||||
// 公众号appSecret
|
||||
configStorage.setSecret(SysConst.getSysConfig().getWxH5AppSecret()); |
||||
return configStorage; |
||||
} |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @Name wxMpService |
||||
* @Description //TODO
|
||||
* @Date 16:24 2022/9/2 |
||||
* @Param [] |
||||
* @Return WxMpService |
||||
*/ |
||||
@Bean |
||||
public WxMpService wxMpService() { |
||||
WxMpService wxMpService = new WxMpServiceImpl(); |
||||
wxMpService.setWxMpConfigStorage(wxMpConfigStorage()); |
||||
return wxMpService; |
||||
} |
||||
} |
@ -1,2 +1,2 @@ |
||||
wxH5AppId=wxb05f4cb44994a960 |
||||
wxH5AppSecret=68b540ebce7a4020420f4e5997b1531b |
||||
wxH5AppId=wxa075e8509802f826 |
||||
wxH5AppSecret=0e606fc1378d35e359fcf3f15570b2c5 |
||||
|
Loading…
Reference in new issue