新建Unity3d工程,在新建工程裏Assets選擇Import Package裏的Custom Package倒入ShareSDK包android
這是由於在ShareSDK裏只有在Android和iOS環境裏纔會定義appKey和appSecret,轉化編譯環境爲Android,選擇菜單裏的File下的Buid Settings,選擇Android和Switch Platform json
綁定ShareSDK腳本到Main Camera對象api
到微信開放平臺https://open.weixin.qq.com/註冊開發者帳號,申請應用取得AppID和AppSecret緩存
應用簽名能夠經過安裝應用和應用簽名apk,輸入應用包名後得到,應用簽名經過開發者後臺菜單裏的資源中內心下載微信
右鍵src文件夾導出 app
選擇以前建立的三個包,選擇輸出目錄C:\Users\Administrator\Desktop\DemoCallback.jar,再把DemoCallback.jar覆蓋到默認的工程目錄下的Assets->Plugins->Android->ShareSDK->libsui
下的Democallback.jar就能夠了spa
新建ShareIt腳本,綁定在MainCamera上 插件
using System.Collections; using System.Collections.Generic; using UnityEngine; using cn.sharesdk.unity3d; using UnityEngine.UI; public class ShareIt : MonoBehaviour { private ShareSDK shareSdk; public Text message; void Start() { message.text = ("開始"); shareSdk = GetComponent<ShareSDK>(); //分享回調事件 shareSdk.shareHandler += ShareResultHandler; } //分享 public void OnShareClick() { ShareContent content = new ShareContent(); ScreenCapture.CaptureScreenshot("capture.png"); content.SetImagePath(Application.persistentDataPath + "/capture.png"); content.SetTitle("標題title"); //分享標題 content.SetShareType(ContentType.Image); shareSdk.ShowPlatformList(null, content, 100, 100); //彈出分享菜單選擇列表 //shareSdk.ShowShareContentEditor(PlatformType.WeChat, content); //指定平臺直接分享 } // 分享結果回調 void ShareResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { //成功 if (state == ResponseState.Success) { message.text = ("share result :"); message.text = (MiniJSON.jsonEncode(result)); } //失敗 else if (state == ResponseState.Fail) { message.text = ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]); } //關閉 else if (state == ResponseState.Cancel) { message.text = ("cancel !"); } else { message.text = "ShareResultHandler = " + state.ToString(); } } //受權 public void OnAuthClick() { //請求微信受權//請求這個受權是爲了獲取用戶信息來第三方登陸 shareSdk.Authorize(PlatformType.WeChat); Debug.Log("OnAuth"); //message.text = ("受權中"); } }