package com;
import okhttp3.*;
import org.bouncycastle.util.encoders.Base64;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
/**
* @author: Seayon
* @date: 2017/12/31
* @time: 21:11
*/
public class Util {
private static final MediaType JSON = MediaType.parse("application/json;charset=utf-8");
private static final String WXGAME_URL = "https://mp.weixin.qq.com/wxagame/wxagame_settlement";
private static final int TIMES = 1000;
private static final String SESSIONID_ERROR = "SESSIONID有误,请检查";
private static String game_data = null;
private static final DecimalFormat decimalFormat1 = new DecimalFormat("#.###");
private static final DecimalFormat decimalFormat2 = new DecimalFormat("#.##");
private static final DecimalFormat decimalFormat3 = new DecimalFormat("###");
private static String getActionData(String sessionKey, String encryptedData, String iv) {
byte[] sessionKeyBy = sessionKey.getBytes();
byte[] en = new byte[0];
try {
en = encryptedData.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] ivBy = iv.getBytes();
byte[] enc = Pkcs7Encoder.encryptOfDiyIV(en, sessionKeyBy, ivBy);
return new String(Base64.toBase64String(enc));
}
static {
JSONArray action = new JSONArray();
JSONArray musicList = new JSONArray();
JSONArray touchList = new JSONArray();
for (int i = 10000; i > 0; i--) {
musicList.put(false);
JSONArray actionData = new JSONArray();
double first = Double.valueOf(decimalFormat1.format(Math.random()));
Double second = Double.valueOf(decimalFormat2.format(Math.random() * 2));
boolean booleFlag = i / 5000 == 0 ? true : false;
actionData.put(first);
actionData.put(second);
actionData.put(booleFlag);
action.put(actionData);
JSONArray touchListData = new JSONArray();
double tFirst = Double.valueOf(decimalFormat3.format(250 - (Math.random() * 10)));
double tSecond = Double.valueOf(decimalFormat3.format(670 - (Math.random() * 20)));
touchListData.put(tFirst);
touchListData.put(tSecond);
touchList.put(touchListData);
}
game_data = "action\":" + action.toString() + ",\"" +
"musicList\":" + musicList.toString() + ",\"" +
"touchList\":" + touchList.toString() + ",\"version\":1}";
}
public static String postData(String score, String session_id) {
String result = null;
JSONObject actionDataInfo = new JSONObject();
actionDataInfo.put("score", Integer.valueOf(score));
actionDataInfo.put("times", TIMES);
actionDataInfo.put("game_data", "{\"seed\":" + System.currentTimeMillis() + "123" + ",\"" + game_data);
String AES_KEY = null;
try {
AES_KEY = session_id.substring(0, 16);
} catch (Exception e) {
return SESSIONID_ERROR;
}
String AES_IV = AES_KEY;
OkHttpClient okHttpClient = new OkHttpClient();
String actionData = Util.getActionData(AES_KEY, actionDataInfo.toString(), AES_IV);
String json = "{\"base_req\":{\"session_id\":\"" + session_id + "\",\"fast\":1},\"action_data\":\"" + actionData + "\"}";
RequestBody requestBody = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(WXGAME_URL)
.header("Accept", "*/*")
.header("Accept-Language", "zh-cn")
.header("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E304 MicroMessenger/6.6.1 NetType/WIFI Language/zh_CN")
.header("Content-Type", "application/json")
.header("Referer", "https://servicewechat.com/wx7c8d593b2c3a7703/5/page-frame.html")
.header("Host", "mp.weixin.qq.com")
.header("Connection", "keep-alive")
.post(requestBody)
.build();
ResponseBody responseBody = null;
try {
responseBody = okHttpClient.newCall(request).execute().body();
result = responseBody.string();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (responseBody != null) {
responseBody.close();
}
}
return result;
}
}
微信跳一跳 解密 JAVA 代码
1星 需积分: 14 2 浏览量
2018-01-05
08:12:47
上传
评论 2
收藏 22KB ZIP 举报
goababc10
- 粉丝: 2
- 资源: 2
最新资源
- UIGF_200852355_202404242026.json
- 基于STM32单片机的智能停车场设计源码+全部资料.zip
- 基于Python+Opencv+keras的实时手势识别系统+源码+文档(期末大作业&课程设计&项目开发)
- 基于LabView+MATLAB的说话人识别系统.zip
- 基于树莓派+OpenCV+Python语言的人脸识别+源码+开发文档(毕业设计&课程设计&项目开发)
- 前端vue框架,后端ssm+springboot框架,网站开发.zip
- 基于springboot的快速开发框架.zip
- 基于springboot的分布式权限管理系统,易读易懂、界面简洁美观.zip
- 基于SpringBoot Mybatis-Plus TypeScript的微服务多租户SaaS管理快速开发框架 .zip
- 论文复现:QA-GNN: Reasoning with Language Models and Knowledge
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈