1. 微信登录
1.
annotationProcessor 'me.luzhuo.android:lib_compiler:1.0.5-SNAPSHOT'
compileOnly 'me.luzhuo.android:lib_compiler:1.0.5-SNAPSHOT'
implementation 'me.luzhuo.android:lib_tencent:1.1.6-SNAPSHOT'
2. 该注解可依附于任意Java类上方
@WeixinLogin(applicationId = BuildConfig.APPLICATION_ID, entryTemplete = WechatLoginTemplate.class)
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
WechatManager.init("wxb546013460427555");
}
}
3.
public void wechatLogin(View view) {
WechatManager wechat = WechatManager.getInstance(this);
wechat.setOnLoginCallback(new IWechatCallback() {
@Override
public void onSuccess(String successMessage) {
Log.e(TAG, "" + code);
}
@Override
public void onError(String errMessage) {
Log.e(TAG, "" + err);
}
});
wechat.login();
}
2. 微信支付
1.
annotationProcessor 'me.luzhuo.android:lib_compiler:1.0.5-SNAPSHOT'
compileOnly 'me.luzhuo.android:lib_compiler:1.0.5-SNAPSHOT'
implementation 'me.luzhuo.android:lib_tencent:1.1.6-SNAPSHOT'
2. 该注解可依附于任意Java类上方
@WeixinPay(applicationId = BuildConfig.APPLICATION_ID, entryTemplete = WechatPayTemplate.class)
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
WechatManager.init("wxb546013460427555");
}
}
3.
public void wechatPay(View view) {
WechatManager wechat = WechatManager.getInstance(this);
wechat.setOnPayCallback(new IWechatCallback() {
@Override
public void onSuccess(String successMessage) {
Log.e(TAG, "支付成功");
}
@Override
public void onError(String errMessage) {
Log.e(TAG, "支付失败");
}
});
wechat.pay("1557796771", "wx25205935184438d4a88c93f51146037200", "R2Gw3phu5KMzMWBr", "1590411575", "53C5477A0892BFD2B15627DD5DCE1C8545687CC534A8E09D4365A572C4C54A05");
}
3. 微信分享
只要分享, 都是成功 (不存在失败的情况, 所以没有回调)
1.
implementation 'me.luzhuo.android:lib_tencent:1.1.6-SNAPSHOT'
implementation 'me.luzhuo.android:lib_core:2.0.1-SNAPSHOT'
// 加载网络图片需要的库 (非必须)
implementation this.rootProject.depsLibs.okhttp
implementation 'me.luzhuo.java.android:lib_network:1.0.2-SNAPSHOT'
2. 该注解可依附于任意Java类上方
@WeixinLogin(applicationId = BuildConfig.APPLICATION_ID, entryTemplete = WechatLoginTemplate.class)
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
WechatManager.init("wxb546013460427555");
}
}
3.
final WechatManager wechat = WechatManager.getInstance(this);
// 分享文本内容
wechat.share(new TextMessage("这是文本分享"), WechatShareWhere.Friend);
// 分享图片
wechat.share(new ImageMessage(this, R.mipmap.image), WechatShareWhere.Friend);
wechat.share(new ImageMessage(this, Environment.getExternalStorageDirectory() + File.separator + "shareimage.jpg" /*内部存储卡*/), WechatShareWhere.Friend);
// 分享音乐
wechat.share(new MusicMessage(this, "http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3", "http://www.qq.com", "音乐标题啊", "音乐描述啊", R.mipmap.image), WechatShareWhere.Friend);
// 分享视频
wechat.share(new VideoMessage(this, "https://vdept.bdstatic.com/5846443970506b655764664834687537/35506d4e50576843/e610799b39f3c277bd7e6a2126a1211ce016cf0ceb260b5f5557d606d020bca4c53e7fe1de9a15cbc4e94bf5d6f5fda3f4101f828384ede0865741a81d17e5ae.mp4?auth_key=1594552495-0-0-d893d9d8b6118bdc4e94a62d855ebcc6", "这是标题哟", "这是描述哟", R.mipmap.image), WechatShareWhere.Collect);
// 分享Web页
wechat.share(new WebMessage(this, "http://www.qq.com", "这是标题哟", "这是描述哟", R.mipmap.image), WechatShareWhere.Friend);
// 需要网络封面的, 参考以下案例
// 1. 直接使用okhttp
// 以网路图片作为封面
Request request = new Request.Builder().url("http://b-ssl.duitang.com/uploads/item/201608/29/20160829203548_YHJjV.thumb.700_0.jpeg").build();
OkHttpClient client = new OkHttpClient();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Toast.makeText(MainActivity.this, "图片下载失败", Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
InputStream inputStream = response.body().byteStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
wechat.share(new MusicMessage("http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3", "http://www.qq.com", "音乐标题啊", "音乐描述啊", bitmap), WechatShareWhere.Friend);
}
});
// 2. 使用 lib_network 库
OKHttpManager okHttpManager = new OKHttpManager();
okHttpManager.getBitmap("http://b-ssl.duitang.com/uploads/item/201608/29/20160829203548_YHJjV.thumb.700_0.jpeg", new IBitmapCallback() {
@Override
public void onSuccess(int i, Bitmap bitmap) {
wechat.share(new MusicMessage("http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3", "http://www.qq.com", "音乐标题啊", "音乐描述啊", bitmap), WechatShareWhere.Friend);
}
@Override
public void onError(int i, String s) {
Toast.makeText(MainActivity.this, "下载图片失败", Toast.LENGTH_SHORT).show();
}
});
1. 分享到小程序
分享的App和小程序要在同一账号下, 如果在不同的账号下, 需要对其他主体的小程序进行绑定
/**
* 分享到小程序
*/
public void wechatShareMiniProgramObject(View view) {
final String miniId = "gh_d5d3de25a329";
final WechatManager wechat = WechatManager.getInstance(this);
// wechat.share(new MiniProgramObject(this, "http://www.qq.com", WXMiniProgramObject.MINIPTOGRAM_TYPE_RELEASE, miniId, "", "这是标题哟", "这是描述哟", R.mipmap.image), WechatShareWhere.Friend);
wechat.share(new MiniProgramObject(this, miniId, "这是标题哟", "这是描述哟", R.mipmap.image), WechatShareWhere.Friend);
}
4. 混淆
# --- weixin ---
-keep class com.tencent.mm.opensdk.** {*;}
-keep class com.tencent.wxop.** {*;}
-keep class com.tencent.mm.sdk.** {*;}