文档地址:https://baiyuliang.blog.csdn.net/article/details/134444104
京东联盟flutter插件地址:https://pub.dev/packages/jdkit
1)将申请的安全图片,safe.jpg放在flutter项目,android主工程res/raw下:
2)从github上,将jdsdk文件夹下载下来,并放入anrdoid主工程下:
3)修改jdsdk中的AndroidMainfest.xml:
<activity
android:name="com.kepler.jd.sdk.KeplerBackActivity"
android:exported="true"
android:theme="@android:style/Theme.Translucent">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sdkback49d5d16d4f8ba1411c2c1533c2308a47" />
intent-filter>
activity>
将scheme:sdkback后的key修改为自己的!
4)android主工程 settings.gradle中添加:include ':jdsdk'
1)将申请的安全图片safe.jpg,放入IOS主工程Runner/bundle文件夹下:
其它配置,请按京东联盟官方文档进行配置!
late WebViewController webViewController;
webViewController = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {},
onPageStarted: (String url) {},
onPageFinished: (String url) {},
onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith('openapp.jdmobile')) {
launchUrlString(request.url);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
);
由于我们不需要展示webview的跳转过程,所以可将webview宽高设为0:
SizedBox(width: 0, height: 0, child: WebViewWidget(controller: webViewController))
webViewController.loadRequest(Uri.parse("https://open-oauth.jd.com/oauth2/to_login?app_key=xxx&response_type=code&redirect_uri=xindongriji://xdrj?event=jdsq&state=20180416&scope=snsapi_alliance_app_base"));
AppScheme? appScheme = AppSchemeImpl.getInstance();
appScheme?.getInitScheme().then((value) {
if (value != null) {
setState(() {
result = "${value.dataString}";
});
}
});
appScheme?.registerSchemeListener().listen((event) {
if (event != null) {
setState(() {
result = "${event.dataString}";
});
}
});
回调的str格式:你的scheme://xdrj?event=jdsq&state=自定义内容原封不动返回&code=xxx,你拿到code后即可请求jd提供的其它接口: