应用宝对应文档地址:https://wiki.open.qq.com/index.php?title=YSDK%E5%90%8E%E5%8F%B0%E6%8E%A5%E5%8F%A3&oldid=47542
如果有用请给我个赞好吗
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
* 这个是手Q的接入,微信的雷同
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String appid = SdkParameter.YSQAPPID; // APPID
String openid = request.getParameter("openid");
String openkey = request.getParameter("openkey");
String userip = request.getParameter("userip");
String appKey = SdkParameter.YSQAPPKEY; // APPKEY
long timestamp = System.currentTimeMillis() / 1000;
String sig = appKey + timestamp;
MD5 md5 = new MD5();
String sign = md5.getMD5ofStr(sig).toLowerCase(); // 全部转小写
/**
* 正式环境 https://ysdk.qq.com/auth/qq_check_token
* 测试环境 https://ysdktest.qq.com/auth/qq_check_token
*/
String url = "https://ysdktest.qq.com/auth/qq_check_token";
StringBuilder sb = new StringBuilder();
sb.append(url)
.append("?timestamp=").append(timestamp)
.append("&appid=").append(appid)
.append("&sig=").append(sign)
.append("&openid=").append(openid)
.append("&openkey=").append(openkey)
.append("&userip=").append(userip);
String str = HttpClient.doGet(sb.toString());
PrintWriter out = response.getWriter();
out.print(str);
out.close();
}
附上MD5
package utils;
import java.lang.reflect.Array;
public class MD5 {
/* 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的,
这里把它们实现成为static final是表示了只读,切能在同一个进程空间内的多个
Instance间共享*/
static final int S11 = 7;
static final int S12 = 12;
static final int S13 = 17;
static final int S14 = 22;
static final int S21 = 5;
static final int S22 = 9;
static final int S23 = 14;
static final int S24 = 20;
static final int S31 = 4;
static final int S32 = 11;
static final int S33 = 16;
static final int S34 = 23;
static final int S41 = 6;
static final int S42 = 10;
static final int S43 = 15;
static final int S44 = 21;
static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 下面的三个成员是MD5计算过程中用到的3个核心数据,在原始的C实现中
被定义到MD5_CTX结构中
*/
private long[] state = new long[4]; // state (ABCD)
private long[] count = new long[2]; // number of bits, modulo 2^64 (lsb first)
private byte[] buffer = new byte[64]; // input buffer
/* digestHexStr是MD5的唯一一个公共成员,是最新一次计算结果的
16进制ASCII表示.
*/
public String digestHexStr;
/* digest,是最新一次计算结果的2进制内部表示,表示128bit的MD5值.
*/
private byte[] digest = new byte[16];
/*
getMD5ofStr是类MD5最主要的公共方法,入口参数是你想要进行MD5变换的字符串
返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
*/
public String getMD5ofStr(String inbuf) {
md5Init();
md5Update(inbuf.getBytes(), inbuf.length());
md5Final();
digestHexStr = "";
for (int i = 0; i < 16; i+&#