本文整理了Java中cn.binarywang.wx.miniapp.api.WxMaService.getWxMaConfig()
方法的一些代码示例,展示了WxMaService.getWxMaConfig()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxMaService.getWxMaConfig()
方法的具体详情如下:
包路径:cn.binarywang.wx.miniapp.api.WxMaService
类名称:WxMaService
方法名:getWxMaConfig
[英]获取WxMaConfig 对象.
[中]获取WxMaConfig对象.
代码示例来源:origin: com.github.binarywang/weixin-java-miniapp
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
Lock lock = this.wxMaService.getWxMaConfig().getCardApiTicketLock();
try {
lock.lock();
if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireCardApiTicket();
}
if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds);
}
} finally {
lock.unlock();
}
return this.wxMaService.getWxMaConfig().getJsapiTicket();
}
代码示例来源:origin: binarywang/WxJava
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
Lock lock = this.wxMaService.getWxMaConfig().getCardApiTicketLock();
try {
lock.lock();
if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireCardApiTicket();
}
if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds);
}
} finally {
lock.unlock();
}
return this.wxMaService.getWxMaConfig().getJsapiTicket();
}
代码示例来源:origin: com.github.binarywang/weixin-java-miniapp
@Override
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
Lock lock = this.wxMaService.getWxMaConfig().getJsapiTicketLock();
try {
lock.lock();
if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireJsapiTicket();
}
if (this.wxMaService.getWxMaConfig().isJsapiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=jsapi", null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateJsapiTicket(jsapiTicket, expiresInSeconds);
}
} finally {
lock.unlock();
}
return this.wxMaService.getWxMaConfig().getJsapiTicket();
}
代码示例来源:origin: binarywang/WxJava
@Override
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
Lock lock = this.wxMaService.getWxMaConfig().getJsapiTicketLock();
try {
lock.lock();
if (forceRefresh) {
this.wxMaService.getWxMaConfig().expireJsapiTicket();
}
if (this.wxMaService.getWxMaConfig().isJsapiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=jsapi", null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateJsapiTicket(jsapiTicket, expiresInSeconds);
}
} finally {
lock.unlock();
}
return this.wxMaService.getWxMaConfig().getJsapiTicket();
}
代码示例来源:origin: binarywang/WxJava
@Override
public void setUserStorage(Map<String, String> kvMap, String sessionKey, String openid) throws WxErrorException {
final WxMaConfig config = this.service.getWxMaConfig();
JsonObject param = new JsonObject();
JsonArray array = new JsonArray();
for (Map.Entry<String, String> e : kvMap.entrySet()) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("key", e.getKey());
jsonObject.addProperty("value", e.getValue());
array.add(jsonObject);
}
param.add("kv_list", array);
String params = param.toString();
String signature = SignUtils.createHmacSha256Sign(params, sessionKey);
String url = String.format("https://api.weixin.qq.com/wxa/set_user_storage" +
"?appid=%s&signature=%s&openid=%s&sig_method=%s",
config.getAppid(), signature, openid, "hmac_sha256");
String result = this.service.post(url, params);
WxError error = WxError.fromJson(result);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-miniapp
@Override
public void setUserStorage(Map<String, String> kvMap, String sessionKey, String openid) throws WxErrorException {
final WxMaConfig config = this.service.getWxMaConfig();
JsonObject param = new JsonObject();
JsonArray array = new JsonArray();
for (Map.Entry<String, String> e : kvMap.entrySet()) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("key", e.getKey());
jsonObject.addProperty("value", e.getValue());
array.add(jsonObject);
}
param.add("kv_list", array);
String params = param.toString();
String signature = SignUtils.createHmacSha256Sign(params, sessionKey);
String url = String.format("https://api.weixin.qq.com/wxa/set_user_storage" +
"?appid=%s&signature=%s&openid=%s&sig_method=%s",
config.getAppid(), signature, openid, "hmac_sha256");
String result = this.service.post(url, params);
WxError error = WxError.fromJson(result);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
}
代码示例来源:origin: ustcwudi/springboot-seed
@RequestParam("timestamp" ) String timestamp,
@RequestParam("nonce" ) String nonce) {
final boolean isJson = Objects.equals(this.wxService.getWxMaConfig().getMsgDataFormat(),
WxMaConstants.MsgDataFormat.JSON);
if (StringUtils.isBlank(encryptType)) {
inMessage = WxMaMessage.fromEncryptedJson(requestBody, this.wxService.getWxMaConfig());
} else {//xml
inMessage = WxMaMessage.fromEncryptedXml(requestBody, this.wxService.getWxMaConfig(),
timestamp, nonce, msgSignature);
代码示例来源:origin: binarywang/weixin-java-miniapp-demo
final boolean isJson = Objects.equals(wxService.getWxMaConfig().getMsgDataFormat(),
WxMaConstants.MsgDataFormat.JSON);
if (StringUtils.isBlank(encryptType)) {
inMessage = WxMaMessage.fromEncryptedJson(requestBody, wxService.getWxMaConfig());
} else {//xml
inMessage = WxMaMessage.fromEncryptedXml(requestBody, wxService.getWxMaConfig(),
timestamp, nonce, msgSignature);
代码示例来源:origin: com.github.binarywang/weixin-java-miniapp
@Override
public byte[] getQrCode(String path) throws WxErrorException {
String appId = this.wxMaService.getWxMaConfig().getAppid();
Path qrCodeFilePath = null;
try {
RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor
.create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("weixin-java-tools-ma-" + appId).toFile());
final StringBuilder url = new StringBuilder(GET_QRCODE_URL);
if (StringUtils.isNotBlank(path)) {
url.append("?path=").append(URLEncoder.encode(path, StandardCharsets.UTF_8.name()));
}
qrCodeFilePath = this.wxMaService.execute(executor, url.toString(), null).toPath();
return Files.readAllBytes(qrCodeFilePath);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
} finally {
if (qrCodeFilePath != null) {
try {
// 及时删除二维码文件,避免积压过多缓存文件
Files.delete(qrCodeFilePath);
} catch (Exception ignored) {
}
}
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public byte[] getQrCode(String path) throws WxErrorException {
String appId = this.wxMaService.getWxMaConfig().getAppid();
Path qrCodeFilePath = null;
try {
RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor
.create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("weixin-java-tools-ma-" + appId).toFile());
final StringBuilder url = new StringBuilder(GET_QRCODE_URL);
if (StringUtils.isNotBlank(path)) {
url.append("?path=").append(URLEncoder.encode(path, StandardCharsets.UTF_8.name()));
}
qrCodeFilePath = this.wxMaService.execute(executor, url.toString(), null).toPath();
return Files.readAllBytes(qrCodeFilePath);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
} finally {
if (qrCodeFilePath != null) {
try {
// 及时删除二维码文件,避免积压过多缓存文件
Files.delete(qrCodeFilePath);
} catch (Exception ignored) {
}
}
}
}
代码示例来源:origin: binarywang/weixin-java-miniapp-demo
@Bean
public Object services() {
maServices = this.properties.getConfigs()
.stream()
.map(a -> {
WxMaInMemoryConfig config = new WxMaInMemoryConfig();
config.setAppid(a.getAppid());
config.setSecret(a.getSecret());
config.setToken(a.getToken());
config.setAesKey(a.getAesKey());
config.setMsgDataFormat(a.getMsgDataFormat());
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
routers.put(a.getAppid(), this.newRouter(service));
return service;
}).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a));
return Boolean.TRUE;
}
代码示例来源:origin: com.github.binarywang/weixin-java-miniapp
@Override
public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
long timestamp = System.currentTimeMillis() / 1000;
String randomStr = RandomUtils.getRandomStr();
String jsapiTicket = getJsapiTicket(false);
String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket,
"noncestr=" + randomStr, "timestamp=" + timestamp, "url=" + url);
return WxJsapiSignature
.builder()
.appId(this.wxMaService.getWxMaConfig().getAppid())
.timestamp(timestamp)
.nonceStr(randomStr)
.url(url)
.signature(signature)
.build();
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
long timestamp = System.currentTimeMillis() / 1000;
String randomStr = RandomUtils.getRandomStr();
String jsapiTicket = getJsapiTicket(false);
String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket,
"noncestr=" + randomStr, "timestamp=" + timestamp, "url=" + url);
return WxJsapiSignature
.builder()
.appId(this.wxMaService.getWxMaConfig().getAppid())
.timestamp(timestamp)
.nonceStr(randomStr)
.url(url)
.signature(signature)
.build();
}
}
内容来源于网络,如有侵权,请联系作者删除!