1.微信开放平台创建应用 点击“创建移动应用”,填写相关信息后提交审核 审核通过后申请分享和登录的权限 2.iOS相关配置 Associated Domains: 在xcode中依次点击:左侧根目录Runner--》TARGETS下的R
点击“创建移动应用”,填写相关信息后提交审核
审核通过后申请分享和登录的权限
Associated Domains:
在xcode中依次点击:左侧根目录Runner--》TARGETS下的Runner--》Signing & Capabilities--》+Capability--》添加Associated Domains
在Domains中填写域名,例如你的域名为www.abc.com,那个填写的格式为:applinks:www.abc.com
apple-app-site-association文件配置
创建文件并在文件内写入:
{ "applinks": { "apps": [], "details": [ { "appID": "teamID.BundleID", "paths": [ "/app static void ShareUrl(String url, {String thumbFile, Uint8List thumbBytes, String title, String desc, int scene = 1, String networkThumb, String assetThumb}) { // 字符串不为空 bool strNoEmpty(String value) { if (value == null) return false; return value.trim().isNotEmpty; } desc = desc ?? ""; title = title ?? ""; if (desc.length > 54) { desc = desc.substring(0, 54) + "..."; } if (title.length > 20) { title = title.substring(0, 20) + "..."; } WeChatScene wxScene = WeChatScene.SESSION; if (scene == 2) { wxScene = WeChatScene.TIMELINE; } else if (scene == 3) { wxScene = WeChatScene.FAVORITE; } WeChatImage image = null; if (thumbFile != null) { image = WeChatImage.file(File(thumbFile)); } else if (thumbBytes != null) { image = WeChatImage.binary(thumbBytes); } else if (strNoEmpty(networkThumb)) { image = WeChatImage.network(Uri.encodeFull(networkThumb)); } else if (strNoEmpty(assetThumb)) { image = WeChatImage.asset(assetThumb, suffix: ".png"); } var model = WeChatShareWEBPageModel( url, thumbnail: image, title: title, description: desc, scene: wxScene, ); shareToWeChat(model); } void ShareImage({String title, String decs, String file, String url, String asset, int scene = 1}) async { WeChatScene wxScene = WeChatScene.SESSION; if (scene == 2) { wxScene = WeChatScene.TIMELINE; } else if (scene == 3) { wxScene = WeChatScene.FAVORITE; } WeChatShareImageModel model = null; if (file != null) { model = WeChatShareImageModel(WeChatImage.file(File(file)), title: title, description: decs, scene: wxScene); } else if (url != null) { model = WeChatShareImageModel(WeChatImage.network(url), title: title, description: decs, scene: wxScene); } else if (asset != null) { model = WeChatShareImageModel(WeChatImage.asset(asset), title: title, description: decs, scene: wxScene); } else { throw Exception("缺少图片资源信息"); } shareToWeChat(model); }}
点击微信登录后先判断是否安装了微信,再发送微信授权
GestureDetector( onTap: (){ //判断是否安装了微信 isWeChatInstalled.then((value){ if(value){ //发送微信授权 sendWeChatAuth(scope: 'snsapi_userinfo', state:"wechat_sdk_demo_test").then((value){ print('拉取微信用户信息:${value}'); }).catchError((e){}); }else{ print('无法打开微信,请检查是否安装了微信'); } }); },)
监听微信授权返回结果,若授权成功则执行登录逻辑
void initState() { _weChatResponseEventHandler();}void _weChatResponseEventHandler(){ weChatResponseEventHandler.distinct((a, b) => a == b).listen((event) { print('监听微信:${event.errCode}'); if(event is WeChatAuthResponse){ int errCode = event.errCode; print('微信登录返回值:ErrCode :${event.errCode} code:${event.code}'); if(errCode == 0){ print('用户同意授权登录'); String code = event.code; // 调接口将code传给后端,执行登陆操作 ...... }else if(errCode == -4){ print('用户拒绝授权登录'); }else if(errCode == -2){ print('用户取消授权登录'); } } });}
来源地址:https://blog.csdn.net/YML_426/article/details/128916526
--结束END--
本文标题: flutter 集成微信登录、分享功能
本文链接: https://www.lsjlt.com/news/387198.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0