现在一些主流的APP都有微信登录 / 支付 / 分享等功能,下面是集成指南
1.需要有微信开发者账号,并且有微信登录 支付的权限
Builder.Gradle中
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'
然后Manifest中
<activity android:name=".wxapi.WXPayEntryActivity" android:exported="true" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="你的id" /> </intent-filter> </activity> <activity android:name=".wxapi.WXEntryActivity" android:exported="true" />
<receiver android:name=".wxapi.AppRegister" android:exported="false"> <intent-filter> <action android:name="com.tencent.mm.plugin.openapi.Intent.ACTION_REFRESH_WXAPP" /> </intent-filter> </receiver>
//在你的包名下新建wxapi包 demo中有
//调起的方法
if (!MainApplication.mWxApi.isWXAppInstalled()) { ToastUtils.show("您的设备未安装微信客户端"); } else { final SendAuth.Req req = new SendAuth.Req(); req.scope = "snsapi_userinfo"; req.state = "wechat_sdk_demo_test"; MainApplication.mWxApi.sendReq(req); }
WXEntryActivity.java/登录分享
WXPayEntryActivity//支付
支付需要后台生成订单 然后调起