赞
踩
ShareSDK接入的是整个untiy 的包 官方直接包含了android 和 ios 所以只需要写接口和处理打包配置文件就行
1:android
:
2:在配置文件里面写回调函数和设置权限 (已经有的直接点击这个就行了)
注意修改这个 AndroidManifest.xml 微信回调要和包名一样
2:微信回调 要根据包名生成不同的DemoCallBack.jar文件
官方工程里面的微信回调改成自己的包名 打包为DemoCallBack.jar文件 替换工程里面的DemoCallBack文件
3:提示语言设置根据手机当前系统语言显示提示 (不会根据游戏内部语言修改而改变)
出现错误 编译完了,在链接时候报的错 这个不是报错,这个不用管 桥接文件里有警告的东西,不用管的
解决报错
这里点击+号,添加下这个JavaScriptCore.framework依赖库
- using UnityEngine;
- using System.Collections;
- using System.IO;
- using cn.sharesdk.unity3d;
- using LuaInterface;
- using LuaFramework;
- using System.Collections.Generic;
-
- public class ShareSDKTool : MonoBehaviour
- {
- //sharesdk实例
- private ShareSDK ssdk;
- //设置lua回调方法
- LuaFunction luaFun;
- //截屏图片名字
- private string ssname = "shareShot.png";
-
- //设置分享参数
- private string strDes = "";
- private string strImagtPath = "";
- private string strUrl = "";
- private string strUrlDes = "";
- private int contentType = 2;
- private string strImageUrl = "";
- private string strTitile = "";
- private string strTitleUrl = "";
- private string strSite = "";
- private string strSiteUrl = "";
- private string strComent = "";
- private string strMusicUrl = "";
-
- void Awake()
- {
- strImagtPath = Path.Combine(Application.temporaryCachePath, ssname);
- }
-
- //初始化sdk
- public void InitShareSDK()
- {
- ssdk = gameObject.GetComponent<ShareSDK>();
- if (ssdk == null)
- {
- ssdk = gameObject.AddComponent<ShareSDK>();
- }
- //设置回调函数
- ssdk.shareHandler = OnShareResultHandler;
- }
-
- //设置分享的参数
- public void InitShareContentPramas(string strdes,string strurl, string strimagtpath, string strurldes, int contenttype,string strimageurl,string strtile,string strtitleurl,string strsite,string strsiteurl,string strcoment,string strmusicurl)
- {
- strDes = strdes;
- strUrl = strurl;
- if(strimagtpath != "")
- {
- strImagtPath = strimagtpath;
- }
- strUrlDes = strurldes;
- contentType = contenttype;
- strImageUrl = strimageurl;
- strTitile = strtile;
- strTitleUrl = strtitleurl;
- strSite = strsite;
- strSiteUrl = strsiteurl;
- strComent = strcoment;
- strMusicUrl = strmusicurl;
- }
-
- //开始设置分享参数
- private ShareContent SetShareContent()
- {
- //分享的内容
- ShareContent content = new ShareContent();
-
- //文本分享 只有一个text
- //设置分享的文字 所有平台都需要这个字段 所有分享类型都需要
- //text分享
- if (contentType == 1)
- {
- if (strDes != "")
- {
- content.SetText(strDes);
- }
- //标题
- if (strTitile != "")
- {
- content.SetTitle(strTitile);
- }
- #if UNITY_ANDROID
- //标题链接
- if (strTitleUrl != "")
- {
- content.SetTitleUrl(strTitleUrl);
- }
- //QQ空间文本
- if (strSite != "")
- {
- content.SetSite(strSite);
- }
- if (strSiteUrl != "")
- {
- content.SetSiteUrl(strSiteUrl);
- }
- #endif
- }
- else
- {
- //图片分享 webpage分享
- if (strDes != "")
- {
- content.SetText(strDes);
- }
- //网络图片路径
- if (strImageUrl != "")
- {
- content.SetImageUrl(strImageUrl);
- }
- else
- {
- content.SetImagePath(strImagtPath); //本地图片路径
- }
- //标题
- if (strTitile != "")
- {
- content.SetTitle(strTitile);
- }
- //Android Only
- #if UNITY_ANDROID
- //标题链接
- if (strTitleUrl != "")
- {
- content.SetTitleUrl(strTitleUrl);
- }
- //QQ空间文本
- if (strSite != "")
- {
- content.SetSite(strSite);
- }
- if (strSiteUrl != "")
- {
- content.SetSiteUrl(strSiteUrl);
- }
- #elif UNITY_IPHONE
- //分享的网站描述
- if (strUrlDes != "")
- {
- content.SetUrlDescription(strUrlDes);
- }
- #endif
- //网页链接
- if (strUrl != "")
- {
- content.SetUrl(strUrl);
- }
- //描述
- if (strComent != "")
- {
- content.SetComment(strComent);
- }
- //音乐链接
- if (strMusicUrl != "")
- {
- content.SetMusicUrl(strMusicUrl);
- }
- }
- //设定分享内容的主要类型,放在最后一步
- content.SetShareType(contentType);
-
- return content;
- }
- //启动分享 通过平台ID
- public void ShareSDKByPlantForm(int plantform, LuaFunction f1)
- {
- PlatformType nowplantform = PlatformType.WeChatMoments;
- ShareContent content = SetShareContent();
- luaFun = f1;
-
- if (plantform == 23)
- {
- nowplantform = PlatformType.WeChatMoments;
- }
- else if (plantform == 22)
- {
- nowplantform = PlatformType.WeChat;
- }
- else if (plantform == 10)
- {
- nowplantform = PlatformType.Facebook;
- }
- else if (plantform == 1)
- {
- nowplantform = PlatformType.SinaWeibo;
- }
- else if (plantform == 24)
- {
- nowplantform = PlatformType.QQ;
- }
- else if (plantform == 6)
- {
- nowplantform = PlatformType.QZone;
- }
-
- ssdk.ShareContent(nowplantform, content);
- }
-
- //分享的结果回调函数
- private void OnShareResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
- {
- int stateNow = 1;
- if (state == ResponseState.Success)
- {
- print("share result :");
- print(MiniJSON.jsonEncode(result));
- stateNow = 1;
- }
- else if (state == ResponseState.Fail)
- {
- print("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
- stateNow = 2;
- }
- else if (state == ResponseState.Cancel)
- {
- print("cancel !");
- stateNow = 3;
- }
-
- Debug.Log("分享的结果回调函数xxxxxxxxxxxxxxxxxxxxxx" + state +"-------"+ stateNow);
- luaFun.Call(stateNow);
- }
-
- //根据不同包 需要不同的分型key 值
- public void SetPlantFormParams(string ssdkID, string ssdkKey, string weichatID, string weichatKey,string qqID, string qqKey, string sinaID, string sinaKey, string facebookID, string facebookKey)
- {
- #if UNITY_ANDROID
- //设置 平台的id
- ssdk.appKey = ssdkID;
- ssdk.appSecret = ssdkKey;
- //微信
- ssdk.devInfo.wechat.AppId = weichatID;
- ssdk.devInfo.wechat.AppSecret = weichatKey;
- ssdk.devInfo.wechatMoments.AppId = weichatID;
- ssdk.devInfo.wechatMoments.AppSecret = weichatKey;
- //QQ
- ssdk.devInfo.qq.AppId = qqID;
- ssdk.devInfo.qq.AppKey = qqKey;
- ssdk.devInfo.qzone.AppId = qqID;
- ssdk.devInfo.qzone.AppKey = qqKey;
- //Sina
- ssdk.devInfo.sinaweibo.AppKey = sinaID;
- ssdk.devInfo.sinaweibo.AppSecret = sinaKey;
- //facebook
- ssdk.devInfo.facebook.ConsumerKey = facebookID;
- ssdk.devInfo.facebook.ConsumerSecret = facebookKey;
-
- #elif UNITY_IPHONE
- //设置 平台的id
- ssdk.appKey = ssdkID;
- ssdk.appSecret = ssdkKey;
- //微信
- ssdk.devInfo.wechat.app_id = weichatID;
- ssdk.devInfo.wechat.app_secret = weichatKey;
- ssdk.devInfo.wechatMoments.app_id = weichatID;
- ssdk.devInfo.wechatMoments.app_secret = weichatKey;
- //QQ
- ssdk.devInfo.qq.app_id = qqID;
- ssdk.devInfo.qq.app_key = qqKey;
- ssdk.devInfo.qzone.app_id = qqID;
- ssdk.devInfo.qzone.app_key = qqKey;
- //Sina
- ssdk.devInfo.sinaweibo.app_key = sinaID;
- ssdk.devInfo.sinaweibo.app_secret = sinaKey;
- //facebook
- ssdk.devInfo.facebook.api_key = facebookID;
- ssdk.devInfo.facebook.app_secret = facebookKey;
-
- #endif
- //设置好参数后再初始化SDK
- ssdk.InitShareSDk();
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。