package com.cms.util;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.cms.Config;
import com.jfinal.kit.HttpKit;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
public class WeixinUtils {
/** 缓存名称 */
public static final String CACHE_NAME = "weixin";
/** CacheManager */
private static final CacheManager CACHE_MANAGER = CacheUtils.getCacheManager();
//=====基本 token 和 ticket
private static final String GET_TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
public static String getAccessToken(String appId,String appSecret){
Ehcache cache = CACHE_MANAGER.getEhcache(CACHE_NAME);
String cacheKey = "accessToken";
Element cacheElement = cache.get(cacheKey);
if (cacheElement == null) {
//======获取开始
String url = String.format(GET_TOKEN_URL, appId, appSecret);
String content= HttpKit.get(url, null);
JSONObject jsonObject = JSONObject.parseObject(content);
System.out.println("======"+jsonObject.toJSONString());
String token = "";
if (null != jsonObject) {
try {
token = jsonObject.getString("access_token");
} catch (JSONException e) {
System.out.println("获取token失败 errcode:" + jsonObject.getIntValue("errcode") + " errmsg:" + jsonObject.getString("errmsg"));
}
}
//======获取结束
cache.put(new Element(cacheKey, token));
cacheElement = cache.get(cacheKey);
}
return (String)cacheElement.getObjectValue();
}
private static final String GET_JSAPI_TICKET_URL="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi";
public static String getJsapiTicket(String accessToken){
Ehcache cache = CACHE_MANAGER.getEhcache(CACHE_NAME);
String cacheKey = "jsapiTicket";
Element cacheElement = cache.get(cacheKey);
if (cacheElement == null) {
//======获取开始
String url = String.format(GET_JSAPI_TICKET_URL,accessToken);
System.out.println(url);
String content= HttpKit.get(url, null);
JSONObject jsonObject = JSONObject.parseObject(content);
String ticket = jsonObject.getString("ticket");
if(StringUtils.isBlank(ticket)){
return null;
}
//======获取结束
cache.put(new Element(cacheKey, ticket));
cacheElement = cache.get(cacheKey);
}
return (String)cacheElement.getObjectValue();
}
//获取用户信息
private static final String GET_USER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN";
//{country=中国, subscribe=1, city=长沙, openid=obknuvpx-L2QwySLwCDBs6VwUuc0, tagid_list=[], sex=1, groupid=0, language=zh_CN, remark=, subscribe_time=1515471683, province=湖南, nickname=樱木, headimgurl=http://wx.qlogo.cn/mmopen/Q3auHgzwzM5N6OYHyYyICmNCHuvT1rBvB81IZ1My8ricRVg3GeHdCCmvXQ1QuGYeXSTEQSjpzXicylicOZibBKIgXw/0}
public static Map<String,Object> getUserInfo(String accessToken,String openId){
String content = HttpKit.get(String.format(GET_USER_INFO_URL, accessToken,openId), null);
System.out.println("GET_USER_INFO_URL=="+content);
return JSONObject.parseObject(content, Map.class);
}
//获取用户auth信息
private static final String GET_AUTHORIZE_URL="https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo&state=%s#wechat_redirect";
public static String getAuthorizeUrl(String appId,String redirectUri,String state){
String url = String.format(GET_AUTHORIZE_URL, appId,redirectUri,state);
System.out.println("url=="+url);
return url;
}
private static final String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
//access_token openid
public static Map<String,Object> getOauth2Token(String appId,String appSecret,String code){
String content = HttpKit.get(String.format(GET_ACCESS_TOKEN_URL, appId,appSecret,code), null);
System.out.println("GET_ACCESS_TOKEN_URL=="+content);
return JSONObject.parseObject(content, Map.class);
}
private static final String GET_OAUTH2_USERINFO_URL= "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN";
//nickname headimgurl
public static Map<String,Object> getOauth2Userinfo(String accessToken,String openId){
String content = HttpKit.get(String.format(GET_OAUTH2_USERINFO_URL, accessToken,openId), null);
System.out.println("GET_OAUTH2_USERINFO_URL=="+content);
return JSONObject.parseObject(content, Map.class);
}
//客服消息
private static final String CUSTOM_SEND_URL="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s";
public static void customSend(String accessToken,String message){
String content = HttpKit.post(String.format(CUSTOM_SEND_URL, accessToken), message);
System.out.println("==CUSTOM_SEND_URL=="+content);
}
//获取文本消息内容
public static String getTextMessage(String touser,String content){
String message="";
message+="{";
message+="\"touser\":\""+touser+"\","; //OPENID
message+="\"msgtype\":\"text\",";
message+="\"text\":";
message+="{";
message+="\"content\":\""+content+"\"";
message+="}";
message+="}";
return message;
}
//获取图片消息内容
public static String getImageMessage(String touser,String mediaId){
String message="";
message+="{";
message+="\"touser\":\""+touser+"\","; //OPENID
message+="\"msgtype\":\"image\",";
message+="\"image\":";
message+="{";
message+="\"media_id\":\""+mediaId+"\"";
message+="}";
message+="}";
return message;
}
//获取语音消息内容
public static String getVoiceMessage(String touser,String mediaId){
String message="";
message+="{";
message+=
没有合适的资源?快使用搜索试试~ 我知道了~
Javaweb在线 农副产品电子商城系统源码(含数据库脚本).zip
共734个文件
png:176个
java:142个
html:131个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 55 浏览量
2022-03-22
13:32:21
上传
评论
收藏 9.58MB ZIP 举报
温馨提示
商品管理(商品分类、商品参数、商品管理) 文章管理(文章分类、文章管理) 会员管理(会员管理) 订单管理(订单管理) 营销管理(广告、广告位、友情链接) 系统管理(角色、管理员、存储插件、地区、设置、模板、清除缓存) 包含手机端、移动端、后台管理
资源详情
资源评论
资源推荐
收起资源包目录
Javaweb在线 农副产品电子商城系统源码(含数据库脚本).zip (734个子文件)
layout.min.css 125KB
style.min.css 119KB
bootstrap.min.css 118KB
checkout_index.css 85KB
comm.css 72KB
cart_index.css 53KB
resys.css 50KB
index.css 50KB
animate.min.css 46KB
list.css 46KB
ueditor.css 45KB
diancai.css 43KB
comm2.css 28KB
beauty_detail.css 27KB
font-awesome.min.css 26KB
style.css 26KB
video-js.css 22KB
member.css 19KB
image.css 19KB
base_bolg.css 16KB
video.css 15KB
attachment.css 15KB
order-list.css 14KB
brand_date.css 13KB
choose_date.css 13KB
about_v3.css 12KB
video-js.min.css 11KB
passport_login.css 9KB
personal.css 9KB
shCoreDefault.css 7KB
global.css 7KB
common.min.css 6KB
datepicker.css 5KB
colorbox.css 5KB
index.css 4KB
scrawl.css 4KB
codemirror.css 3KB
base_v3.css 3KB
charts.css 3KB
information.css 2KB
background.css 2KB
emotion.css 2KB
dialogbase.css 2KB
login.min.css 2KB
music.css 2KB
global.css 2KB
edittable.css 1KB
template.css 1KB
infolist.css 960B
webuploader.css 543B
webuploader.css 543B
help.css 395B
WdatePicker.css 169B
fontawesome-webfontd41d.eot 67KB
fontawesome-webfont93e3.eot 67KB
ElegantIcons.eot 58KB
glyphicons-halflings-regulard41d.eot 20KB
glyphicons-halflings-regular.eot 20KB
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
beauty_imgs_new.gif 27KB
bface.gif 27KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
cface.gif 8KB
loading32.gif 6KB
loading_p.gif 4KB
loading_a.gif 4KB
icons-all.gif 4KB
btn_loading.gif 3KB
loading.gif 3KB
mobile_icon.gif 2KB
loading.gif 2KB
loading-upload.gif 2KB
videologo.gif 2KB
DPshopcarIco.gif 1KB
cancelbutton.gif 1KB
button-bg.gif 1KB
lock.gif 1KB
alignicon.gif 1KB
datePicker.gif 1KB
word.gif 1019B
icon_doc.gif 1012B
icon_psd.gif 1009B
icon_rar.gif 1007B
icon_xls.gif 1005B
icon_mv.gif 1001B
icon_ppt.gif 1001B
icon_pdf.gif 996B
icon_mp3.gif 986B
icon_txt.gif 970B
icon_jpg.gif 950B
icon_exe.gif 949B
icon_chm.gif 923B
共 734 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
等天晴i
- 粉丝: 5981
- 资源: 10万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (GUI框架)Matlab设计_口罩识别检测.zip
- (GUI框架)Matlab设计_垃圾分类系统.zip
- (GUI框架)Matlab设计_垃圾识别定位.zip
- (GUI框架)Matlab设计_疲劳检测GUI设计.zip
- (GUI框架)Matlab设计_疲劳专注度检测系统.zip
- (GUI框架)Matlab设计_苹果水果分级.zip
- (GUI框架)Matlab设计_脐橙水果分级.zip
- (GUI框架)Matlab设计_漂浮物识别.zip
- (GUI框架)Matlab设计_人脸门禁系统.zip
- java组件 敏感信息检测提高信息安全性
- (GUI框架)Matlab设计_人脸考勤设计.zip
- (GUI框架)Matlab设计_人脸购物系统.zip
- (GUI框架)Matlab设计_人脸识别.zip
- (GUI框架)Matlab设计_人脸识别系统.zip
- 永磁同步旋转电机发电并网控制仿真模型(可讲解) 联系本链接包括以下部分: 1. 仿真中含永磁同步发电机(PMSG)、三相整流桥、三相逆变桥、三相电网、整流桥控制模块(发电控制)、逆变桥控制模块(并网控
- (GUI框架)Matlab设计_手势控制系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0