资源简介
微信JS-SDK微信分享接口开发(实用版)代码包.zip
代码片段和文件信息
package com.sitechasia.ebiz.weixin.action;
import java.util.Calendar;
import net.rubyeye.xmemcached.MemcachedClient;
import net.sf.json.JSONobject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.google.gson.Jsonobject;
public class WeiXinShareAction {
/** memCached缓存 */
private MemcachedClient remoteMemcachedClient;
public void getWxShareData() throws Exception {
Jsonobject jsonobject = new Jsonobject();
String ticket = null;
String[] wxInfo = new String[]{“appId““appsecret“};
String ticketResString = this.getShareJsapiTicket(wxInfo);
if (StringUtils.isNotEmpty(ticketResString)) {
JSONobject ticketJSONobject = JSONobject.fromobject(ticketResString);
if (ticketJSONobject.getInt(“errcode“) == 0) {
ticket = JSONobject.fromobject(ticketResString).optString(“ticket“ ““);
}
}
if (StringUtils.isEmpty(ticket)) {
jsonobject.addProperty(“errcode“ 10002);
jsonobject.addProperty(“errmsg“ “ticket_error“);
this.responseWrite(jsonobject.toString());
return;
}
String noncestr = this.createNonceStr();
int timestamp = this.createTimestamp();
String requestRefererURL = this.getRequest().getHeader(“referer“);
logger.warn(“requestRefererURL: “ + requestRefererURL);
String signature = this.createSignature(noncestr ticket timestamp requestRefererURL);
jsonobject.addProperty(“errcode“ 0);
jsonobject.addProperty(“errmsg“ ““);
jsonobject.addProperty(“wxuser“ wxInfo[0]); // appId
jsonobject.addProperty(“timestamp“ timestamp);
jsonobject.addProperty(“noncestr“ noncestr);
jsonobject.addProperty(“signature“ signature);
jsonobject.addProperty(“shareimg“ “http://www.abc.com/123.jpg“);
jsonobject.addProperty(“shareurl“ “http://www.abc.com/123.html“);
this.responseWrite(jsonobject.toString());
}
// 数据签名
private String createSignature(String nocestr String ticket int timestamp String url) {
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
String s = “jsapi_ticket=“ + ticket + “&noncestr=“ + nocestr
+ “×tamp=“ + timestamp + “&url=“ + url;
return DigestUtils.shaHex(s);
}
// 创建随机串 自定义个数0 < ? < 32
private String createNonceStr() {
String str = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789“;
String nonceStr = ““;
for (int i = 0; i < 16; i++) {
int beginIndex = (int) Math.round(Math.random() * 10);
nonceStr += str.substring(beginIndex beginIndex + 1);
}
return nonceStr;
}
// 创建时间戳
private int createTimestamp() {
return Calendar.getInstance().get(Calendar.SECOND);
}
/**
* 微信分享,获取access_token
*/
private String getShareJsapiTicket(String[] wxInfo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5972 2017-06-27 15:49 WeiXinShareAction.java
文件 953 2017-06-27 15:36 jq.wxShare.js
文件 1171 2017-06-27 15:37 jq.wxShare_data.js
- 上一篇:sfark转sf2
- 下一篇:sendpcap发包小软件
相关资源
- arcgis_enterprise10.7.txt
- vmwareworkstationpro15.0.2.txt
- 80端口宽带账号密码爆破工具最新版
- 拔河游戏.rar
- 几十个开源项目28G设计资料,适用于
- example.zip
- Anaconda3-4.2.0-Windows-x86_64.txt
- unity-横向比较unity3d与其他的游戏引擎
- VS2008CWinpcap网络嗅探器中科院课设.r
- abaqus二维切削仿真.inp
- studentmanageprogect.zip
- SunLikeERP8.0.txt
- 2019年东南大学研究生自辩、中特复习
- 国内外管理信息系统现状及展望
- IEEE33.DAT
- IEMOCAP.txt
- 无忧2019全国计算机等级考试破解补丁
- L_8086_8259_8255_8253.pdsprj
- ieee33.rar
- 美国疫情数据.xlsx
- 枪神纪全功能源码.rar
- VirtualAudioCable4.60Win10版.rar
- 多路串口.7z
-
twoli
nks.slx - MOPSO.zip124181
- 新建DOCX文档.docx
- 决策树算法.rar
- 锁相环的改进及仿真_李尧.pdf
- 新建压缩(zipped)文件夹.zip
- 9-Axis.zip
评论
共有 条评论