**
**
闲话不多说,之前一直奇怪微信抢红包是怎么玩的,直到了解到**Xposed框架,**没错就是它,一个神奇的东西!
近期有朋友说要搞个小游戏,了解到微信,支付宝个人收款,于是研究了一番,仅此记录一波!
有Xposed框架的支持,理论上是可以实现的,大概流程如下
1:游戏端点击收款,发送到服务器
2:服务器下发收款信息到手机端
3:手机端收到消息通过Xposed调起微信收款吗界面,并生成对应二维码,上传到服务器
4:游戏端展现收款码给用户
5:用户付款后手机端收到消息,通过Xposed拦截后通知服务器,最后订单完成!!!
大概流程就是这样,下面是一些关键源码
/**
* 开始Hook二维码创建窗口,目的是为了创建生成二维码
*
* @param appClassLoader
* @throws Exception
*/
private void hookQRWindows(final ClassLoader appClassLoader) {
Class> clazz = XposedHelpers.findClass("com.tencent.mm.plugin.collect.ui.CollectCreateQRCodeUI", appClassLoader);
XposedBridge.hookAllMethods(clazz, "onCreate", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
}
@Override
protected void afterHookedMethod(MethodHookParam param) {
LogUtils.show("Hook到微信窗口");
((Activity) param.thisObject).getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
});
XposedHelpers.findAndHookMethod("com.tencent.mm.plugin.collect.ui.CollectCreateQRCodeUI", appClassLoader, "initView",
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
}
@Override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {
LogUtils.show("Hook微信开始......");
Intent intent = ((Activity) param.thisObject).getIntent();
String mark = intent.getStringExtra("mark");
String money = intent.getStringExtra("money");
Class> bs = XposedHelpers.findClass("com.tencent.mm.plugin.collect.b.s", appClassLoader);
Object obj = XposedHelpers.newInstance(bs, Double.valueOf(money), "1", mark);
XposedHelpers.callMethod(param.thisObject, "a", obj, true, true);
}
});
}
/**
* Hook微信收到订单消息后的处理
*
* @param appClassLoader
* @param context
*/
private void hookBill(final ClassLoader appClassLoader, final Context context) {
XposedHelpers.findAndHookMethod("com.tencent.wcdb.database.SQLiteDatabase", appClassLoader, "insert", String.class, String.class, ContentValues.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
try {
ContentValues contentValues = (ContentValues) param.args[2];
String tableName = (String) param.args[0];
if (TextUtils.isEmpty(tableName) || !tableName.equals("message")) {
return;
}
Integer type = contentValues.getAsInteger("type");
if (null == type) {
return;
}
if (type == 318767153) {
JSONObject msg = XmlToJson.documentToJSONObject(contentValues.getAsString("content"))
.getJSONObject("appmsg");
if (!msg.getString("type").equals("5")) {
//首款类型type为5
return;
}
QrBean qrBean = new QrBean();
qrBean.setChannel(QrBean.WECHAT);
qrBean.setMoney((int) (Float.valueOf(msg.getJSONObject("mmreader")
.getJSONObject("template_detail")
.getJSONObject("line_content")
.getJSONObject("topline")
.getJSONObject("value")
.getString("word")
.replace("¥", "")) * 100));
qrBean.setOrder_id(msg.getString("template_id"));
JSONArray lines = msg.getJSONObject("mmreader")
.getJSONObject("template_detail")
.getJSONObject("line_content")
.getJSONObject("lines")
.getJSONArray("line");
for (int i = 0; i < 2; i++) {
if (lines.size() < i + 1 && lines.getJSONObject(i) == null) {
break;
}
if (lines.getJSONObject(i)
.getJSONObject("key")
.getString("word").contains("付款方")) {
qrBean.setMark_buy(lines.getJSONObject(i)
.getJSONObject("value")
.getString("word"));
} else if (lines.getJSONObject(i)
.getJSONObject("key")
.getString("word").contains("收款方")) {
qrBean.setMark_sell(lines.getJSONObject(i)
.getJSONObject("value")
.getString("word"));
}
}
LogUtils.show("微信收到支付订单:" + qrBean.getOrder_id()
+ "|" + qrBean.getMoney() + "|" + qrBean.getMark_sell() + "|" + qrBean.getMark_buy());
Intent broadCastIntent = new Intent();
broadCastIntent.putExtra("data", qrBean.toString());
broadCastIntent.setAction(HookMain.RECEIVE_BILL_WECHAT);
context.sendBroadcast(broadCastIntent);
}
} catch (Exception e) {
LogUtils.show(e.getMessage());
}
}
@Override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {
}
});
}
主要就这两个,当然支付宝也一样需要监听,项目还没有完成,这里就先不贴源码了,
**
**
未解决问题:
1:需要添加多个通道,提高并发效率
2:需要管理对应订单
3:是否可以提前生成一批二维码
4:…