# 开通

  • Log in to the WeChat Open Platform, add a mobile application and submit it for review. After the review, you can get the App ID (AppID)
  • Confirm in the application details that you have obtained the Share to Moments, Share to Friends and other interfaces
  • After configuring appid and iOS universal link in HBuilderX, you can package and use WeChat sharing function

For more information, please refer to the official WeChat document Share and Favorites

# 配置

  • appid 微信开放平台申请应用的AppID值
  • UniversalLinks iOS平台通用链接,必须与微信开放平台配置的一致,推荐使用一键生成iOS通用链接

Notice

  • The standard real machine running base in HBuilderX uses the AppID and other information that DCloud applies for the HBuilder application, which is only used to experience the WeChat sharing function
  • The configuration parameters need to be submitted to the cloud to be packaged to take effect. Please use the [custom debugging base] when the real machine is running (https://ask.dcloud.net.cn/article/35115)

# 使用微信分享

# 示例代码

  • uni-app项目
uni.share({
	provider: "weixin",
	scene: "WXSceneSession",
	type: 1,
	success: function (res) {
		console.log("success:" + JSON.stringify(res));
	},
	fail: function (err) {
		console.log("fail:" + JSON.stringify(err));
	}
});
  • 5+ App项目
var weixinShare = null;
plus.share.getServices(function(services) {
	for (var i in services) {
		var service = services[i];
		// 获取微信分享对象
		if (service.id == 'weixin') {
			weixinShare = service;
			break;
		}
	}
	weixinShare.send( {
	}, function(){
		// 分享成功
	}, function(err) {
    // 分享操作失败
    // err.code is the error code
	})
}, function(err) {
	// Failed to get services
})