闲聊sdk接入说明

上传人:工**** 文档编号:567958806 上传时间:2024-07-22 格式:PDF 页数:30 大小:980.91KB
返回 下载 相关 举报
闲聊sdk接入说明_第1页
第1页 / 共30页
闲聊sdk接入说明_第2页
第2页 / 共30页
闲聊sdk接入说明_第3页
第3页 / 共30页
闲聊sdk接入说明_第4页
第4页 / 共30页
闲聊sdk接入说明_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《闲聊sdk接入说明》由会员分享,可在线阅读,更多相关《闲聊sdk接入说明(30页珍藏版)》请在金锄头文库上搜索。

1、闲聊闲聊 SDKSDK 接入接入以下是游戏需求(Ctrl 点击进入超链接):游戏场景图需求补充:游戏头像以及昵称按照最先点击登录的类型处理, 即先点击哪种登录方式, 就以该种登录方式显示。以下是闲聊给出的文档:闲聊安卓开发文档闲聊 IOS 开发文档闲聊 server 开发文档以下是闲聊给出的 demo在开发过程中闲聊有更换sdk,所以他们的 demo 仅做参考:安卓_demoIOS_demo以下是河南麻将项目接入文档并未完全按照闲聊所给文档接入:一、安卓篇一、安卓篇1.在 Eclipse 内导入。2.在 android 项目内添加位置为:henmjandroidsrccomhappyplayh

2、nmjsgapi3.在 android 项目内添加 My、三个文件位置为:henmjandroidsrcorgcocos2dxjavascript4.在 android 项目内修改1).添加以下内容/xianliaoimport org.sugram.im.sdk.api.ISGAPI;import org.sugram.im.sdk.api.SGAPIFactory;import org.sugram.im.sdk.constants.SGConstants;import org.sugram.im.sdk.modelmsg.SGGameObject;import org.sugram.im

3、.sdk.modelmsg.SGImageObject;import org.sugram.im.sdk.modelmsg.SGMediaMessage;import org.sugram.im.sdk.modelmsg.SGTextObject;import org.sugram.im.sdk.modelmsg.SendMessageToSG;2).在 AppActivity 里添加public class AppActivity extends Cocos2dxActivity ./ xianliaopublic ISGAPI sgApi;3).在 onCreate 函数内添加public

4、 void onCreate(Bundle savedInstanceState) .xianLiaoInit();/get intent data from XianLiaoActivityBundle bundle = getIntent().getExtras();if(bundle != null)String msg =bundle.getString(XL_InviteGameInfo);xlInviteGameInfo = msg;Log.i(getIntent,getIntent_XL_InviteGameInfo:+msg);.try .this.writeFileData(

5、xianliao.txt, has xianliao); catch (IOException e) .public static String XL_AppID = xxxxxxxxxx 闲聊审核获得 xxxxxxxxxx;public static String XL_AppSecret = xxxxxxxx 闲聊审核获得 xxxxxxxxxx;public String xlInviteGameInfo = ;.4).添加函数 RunJS_obj/param 是 对象的public void RunJS_obj(String name, String param)Cocos2dxHelp

6、er.runOnGLThread(new Runnable() String js;String para;Overridepublic void run() / TODO Auto-generated method stubString command = cc.eventManager.dispatchCustomEvent( + js + , + para +);org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge.evalString(command);public Runnable setjs(String js, String pa) this

7、.js = js;this.para = pa;return this;).setjs(name, param);5).添加函数 xianLiaoInitpublic void xianLiaoInit() / 通过 SGAPIFactory 工厂,获取 ISGAPI 实sgApi = SGAPIFactory.createSGAPI(this, XL_AppID);sgApi.registerApp(XL_AppID);6).修改微信登录函数 wxLogin把 SendAuth.Req req = new SendAuth.Req();改为 com.tencent.mm.sdk.modelm

8、sg.SendAuth.Req req=new com.tencent.mm.sdk.modelmsg.SendAuth.Req();7).添加函数 xianLiaoLoginpublic void xianLiaoLogin() if(isXLInstall()org.sugram.im.sdk.modelmsg.SendAuth.Req req = new org.sugram.im.sdk.modelmsg.SendAuth.Req();req.state = none;sgApi.sendReq(req);8).添加函数 isXLInstall/判断闲聊是否安装public boole

9、an isXLInstall()boolean haveXL = sgApi.isSGAppInstalled();if(haveXL)return true;elsedoWithoutXLApp();return false;9).添加函数 doWithoutXLApp/have no xl apppublic void doWithoutXLApp()Log.i(xianliao,doWithoutXLApp);Intent viewIntent = new Intent(android.intent.action.VIEW,Uri.parse(/o/simple.jsp?pkgname=

10、org.xianliao);startActivity(viewIntent);10).添加函数 xlShareTextpublic void xlShareText(String text) if(isXLInstall()/ 初始化一个 SGTextObject 对象,填写分享的文本内容SGTextObject textObject = new SGTextObject();textObject.text = text;/ 用 SGTextObject 对象初始化一个 SGMediaMessage 对象SGMediaMessage msg = new SGMediaMessage();ms

11、g.mediaObject = textObject;/ 构造一个 ReqSendMessageToSG.Req req = new SendMessageToSG.Req();req.transaction = SGConstants.T_TEXT;/ 分享文本req.mediaMessage = msg;req.scene = SendMessageToSG.Req.SGSceneSession; / 代表分享到会话表/ 调用 api 接口发送数据到闲聊sgApi.sendReq(req);11).添加函数 xlShareInviteGamepublic void xlShareInvit

12、eGame(String roomId, String roomToken,String title, Stringdescription) if(isXLInstall()Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon);/ 初始化一个 SGGameObject 对象,设置所分享的游戏图片内容SGGameObject gameObject = new SGGameObject(bitmap);表gameObject.roomId = roomId;gameObject.roomToken

13、= roomToken;/ 用 SGGameObject 对象初始化一个 SGMediaMessage 对象SGMediaMessage msg = new SGMediaMessage();msg.mediaObject = gameObject;msg.title = title;msg.description = description;/ 构造一个 ReqSendMessageToSG.Req req = new SendMessageToSG.Req();req.transaction = SGConstants.T_GAME;req.mediaMessage = msg;req.s

14、cene = SendMessageToSG.Req.SGSceneSession; / 代表分享到会话/ 调用 api 接口发送数据到闲聊sgApi.sendReq(req);12).添加函数 xlShareTexturepublic void xlShareTexture(String path) if(isXLInstall()Bitmap bitmap = BitmapFactory.decodeFile(path);/ 初始化一个 SGImageObject 对象,设置所分享的图片内容SGImageObject imageObject = new SGImageObject(Bitm

15、ap.createScaledBitmap(bitmap,1000,(int) (bitmap.getHeight() / (bitmap.getWidth() / 1000f),true);/ 用 SGImageObject 对象初始化一个 SGMediaMessage 对象SGMediaMessage msg = new SGMediaMessage();msg.mediaObject = imageObject;/ 构造一个 ReqSendMessageToSG.Req req = new SendMessageToSG.Req();req.transaction = SGConstan

16、ts.T_IMAGE;req.mediaMessage = msg;req.scene = SendMessageToSG.Req.SGSceneSession; / 代表分享到会话列表/ 调用 api 接口发送数据到 SugramsgApi.sendReq(req);13).添加函数 GetXLInviteGameInfopublic void GetXLInviteGameInfo()String rtn_msg = xlInviteGameInfo;if(rtn_msg != )RunJS_obj(XL_InviteGameInfo,rtn_msg);xlInviteGameInfo =

17、 ;14).添加函数 StartXianLiaoLoginpublic static void StartXianLiaoLogin() if (ccActivity != null) ccActivity.xianLiaoLogin();15).添加函数 StartShareTextToXLpublic static void StartShareTextToXL(String path) if (ccActivity != null) ccActivity.xlShareText(path);16).添加函数 StartShareInviteGameToXLpublic static vo

18、id StartShareInviteGameToXL(String roomId,String roomToken, String title, String description) if (ccActivity != null) ccActivity.xlShareInviteGame(roomId, roomToken, title, description);17).添加函数 StartShareTextureToXLpublic static void StartShareTextureToXL(String path) if (ccActivity != null) ccActi

19、vity.xlShareTexture(path);18).添加函数 xlGetInviteGameInfopublic static void xlGetInviteGameInfo()if (ccActivity != null) ccActivity.GetXLInviteGameInfo();19).在中添加二、二、JSJS 篇篇1.在中修改函数,在函数中添加以下内容jsclient.logout = function () if (jsclient.remoteCfg.Login) sys.localStorage.removeItem(WX_USER_LOGIN);sys.loca

20、lStorage.removeItem(XL_USER_LOGIN);sys.localStorage.removeItem(LoginType);sys.localStorage.removeItem(loginData);sendEvent(logout);else jsclient.block();jsclient.gamenet.request(pkcon.handler.logout, ,function () sys.localStorage.removeItem(WX_USER_LOGIN);sys.localStorage.removeItem(XL_USER_LOGIN);s

21、ys.localStorage.removeItem(LoginType);sys.localStorage.removeItem(loginData);sendEvent(logout);jsclient.unblock(););2.在中添加函数 getWXunionidjsclient.getWXunionid = function () var unionid = ;var WX_USER_LOGIN = sys.localStorage.getItem(WX_USER_LOGIN);if(WX_USER_LOGIN)WX_USER_LOGIN = JSON.parse(WX_USER_

22、LOGIN);unionid = WX_USER_LOGIN.unionid;return unionid;3.在中添加函数 operateFirstLoginTypejsclient.operateFirstLoginType = function (type) if(!type)var loginType = sys.localStorage.getItem(LoginType);if(loginType)return loginType;else if(type) sys.localStorage.setItem(LoginType, type);return type;elseretu

23、rn null;4.在中添加函数 doInviteGameInfojsclient.doInviteGameInfo = function (para) if(!para)return;/玩家还未登陆if (jsclient.loginui) jsclient.showMsgDelay(0.2,请先登陆游戏后再次点击游戏约局信息!);/玩家已经登录-未在房间内else if (!jsclient.data.sData) jsclient.joinGame(para.roomId, para.roomToken.gameType);/玩家已经登录-在房间内else if (jsclient.da

24、ta.sData) var sData = jsclient.data.sData;var tData = sData.tData;var xl_type = para.roomToken.gameType;var xl_roomid = para.roomId;var pp_type = sData.gameid;var pp_roomid = tData.tableid;if(xl_type!=pp_type | xl_roomid!=pp_roomid)jsclient.showMsgDelay(0.2, 您现在已经在游戏中, 请先退出当前房间后再次点击游戏约局信息!);5.在中添加函数

25、 xlCheckAndSharejsclient.xlCheckAndShare = function () /检查是否进行过闲聊授权 此处为第二处可以关联微信、 闲聊、 皮皮账号的地方 ,如果没有就进行闲聊授权登录var XL_USER_LOGIN = sys.localStorage.getItem(XL_USER_LOGIN);if(!XL_USER_LOGIN)if (jsclient.native)jsclient.native.xlLogin();return;/进行函数调用if(jsclient.xianLiaoPara)var para = jsclient.xianLiaoP

26、ara;if(para.type = XianLiaoType.text)var text = para.text;jsclient.native.xlShareText(text);else if(para.type = XianLiaoType.image)jsclient.native.xlShareImage();/文本/图片else /游戏邀请var roomId = para.roomId;var roomToken = para.roomToken;var title = para.title;var description = para.description;jsclient

27、.native.xlInviteGame(roomId,roomToken,title,description);6.在中添加函数 showMsgDelayjsclient.showMsgDelay = function (delay, msg, yesfunc, nofunc, style) if (jsclient.Scene) jsclient.Scene.scheduleOnce(function () jsclient.showMsg(msg, yesfunc, nofunc, style);,delay);7.在中的中的 initSceneData消息中添加 xlGetInvite

28、GameInfo的函数调用initSceneData: 0, function (d) .if (d.tData.roundNum 0) .else .jsclient.native.xlGetInviteGameInfo();,9.在中的 JSScene 的 jsBind 中添加 XL_InviteGameInfo消息XL_InviteGameInfo: function (para) jsclient.doInviteGameInfo(para);,10.在中的中添加 xlLogin 函数xlLogin: function () try if (cc.sys.OS_ANDROID = cc

29、.sys.os) jsb.reflection.callStaticMethod(org.cocos2dx.javascript.AppActivity, StartXianLiaoLogin, ()V);else if (cc.sys.OS_IOS = cc.sys.os) jsb.reflection.callStaticMethod(AppController, sendXLRequest); catch (e) jsclient.native.HelloOC(xianLiaoLogin throw: + JSON.stringify(e);,11.在中的中添加 xlInviteGame

30、函数xlInviteGame:function (roomId,roomToken,title,description) try if (cc.sys.OS_ANDROID = cc.sys.os) jsb.reflection.callStaticMethod(org.cocos2dx.javascript.AppActivity,StartShareInviteGameToXL,(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V,roomId, roomToken, title, descr

31、iption);else if (cc.sys.OS_IOS = cc.sys.os) jsb.reflection.callStaticMethod(AppController,xlShareInvite:AndID:AndTitle:AndText:,roomToken,roomId,title,description); catch (e) jsclient.native.HelloOC(XLInviteGame throw: + JSON.stringify(e);,12.在中的中添加 xlShareImage函数xlShareImage:function () try var wri

32、tePath = jsb.fileUtils.getWritablePath();var textrueName = wxcapture_screen.png;if (cc.sys.OS_ANDROID = cc.sys.os) jsb.reflection.callStaticMethod(org.cocos2dx.javascript.AppActivity,StartShareTextureToXL,(Ljava/lang/String;)V,writePath + textrueName);else if (cc.sys.OS_IOS = cc.sys.os) var writePat

33、h = jsb.fileUtils.getWritablePath();var textrueName = wxcapture_screen.png;jsb.reflection.callStaticMethod(AppController,xlShareImage:,writePath + textrueName); catch (e) jsclient.native.HelloOC(XLShareImage throw: + JSON.stringify(e);,13.在中的中添加 xlShareText函数xlShareText:function (text) try if (cc.sy

34、s.OS_ANDROID = cc.sys.os) jsb.reflection.callStaticMethod(org.cocos2dx.javascript.AppActivity,StartShareTextToXL,(Ljava/lang/String;)V,text);else if (cc.sys.OS_IOS = cc.sys.os) jsb.reflection.callStaticMethod(AppController,xlShareText:AndText:,【四方河南麻将】,text); catch (e) jsclient.native.HelloOC(xlShar

35、eText throw: + JSON.stringify(e);,14.在中的中添加 xlGetInviteGameInfo函数xlGetInviteGameInfo:function () .try if (cc.sys.OS_ANDROID = cc.sys.os) jsb.reflection.callStaticMethod(org.cocos2dx.javascript.AppActivity, xlGetInviteGameInfo, ()V);else if (cc.sys.OS_IOS = cc.sys.os) jsb.reflection.callStaticMethod(

36、AppController, xlGetInviteGameInfo); catch (e) jsclient.native.HelloOC(xlGetInviteGameInfo throw: + JSON.stringify(e);,15.在中添加变量 xlLoginPara = ;16.在中的 f_login 函数中添加:if(xlLoginPara.useSugram)loginData.useSugram = xlLoginPara.useSugram;loginData.xl_unionid = xlLoginPara.xl_unionid;loginData.xl_nicknam

37、e = xlLoginPara.xl_nickname;loginData.xl_headimgurl = xlLoginPara.xl_headimgurl;17.在中修改函数 autoLoginjsclient.autoLogin = function () jsclient.block();var type = jsclient.operateFirstLoginType();var beginLogin = false;mylog(判断是否可以进行闲聊或者微信的自动登录 type: + type);if (type = wx) mylog(开始进行微信自动登录.);var WX_USE

38、R_LOGIN = sys.localStorage.getItem(WX_USER_LOGIN);if (WX_USER_LOGIN) mylog(微信自动登录.);WX_USER_LOGIN = JSON.parse(WX_USER_LOGIN);LoginAsWeChat(WX_USER_LOGIN);beginLogin = true;else if (type = xl) mylog(开始进行闲聊自动登录.);var XL_USER_LOGIN = sys.localStorage.getItem(XL_USER_LOGIN);if (XL_USER_LOGIN) mylog(闲聊自

39、动登录.);XL_USER_LOGIN = JSON.parse(XL_USER_LOGIN);/mylog(XL_USER_LOGIN info: + XL_USER_LOGIN);/闲聊登录信息初始化xlLoginPara.useSugram = true;xlLoginPara.xl_unionid = XL_USER_LOGIN.openId;xlLoginPara.xl_nickname = XL_USER_LOGIN.nickName;xlLoginPara.xl_headimgurl = XL_USER_LOGIN.smallAvatar;/闲聊登录f_login(xlLogin

40、Para);beginLogin = true;else mylog(开始进行 loginData自动登录.);loginData = sys.localStorage.getItem(loginData);if (loginData) mylog(loginData自动登录.);loginData = JSON.parse(loginData);f_login(loginData.mail, loginData.code);beginLogin = true;/在不能自动登录的时候去判断并执行是否是从游戏邀请链接启动的游戏if (!beginLogin) jsclient.native.xl

41、GetInviteGameInfo();18.在中 LoginLayer的 wechatLogin 事件中添加:在里自己定义一个 varvar iswxLoginiswxLogin = = false;false;_click: function (btn, etype) if (agreeNode.isSelected() /点击微信登录就清除闲聊的登录信息 保证点什么登录游戏内就是该登录方式的信息xlLoginPara = ;if (jsclient.native)iswxLogin = true;iswxLogin = true;jsclient.native.wxLogin();els

42、eLoginAsGuest();,19.在中 LoginLayer添加按钮 xianLiaoLogin 的事件xianLiaoLogin: _visible: function () if (cc.sys.OS_WINDOWS = cc.sys.os | jsclient.remoteCfg.guestLogin /*| jsclient.sdk_control.xianliao*/) return false;else return true;,_run: function () doLayout(this, 0.6, 0.13, 0.5, 0.5, 1.2, -2);,_click: fu

43、nction () mylog(点击闲聊登录);if (jsclient.native)jsclient.native.xlLogin();,20.在中_event 内添加 XL_USER_LOGIN 的事件响应XL_USER_LOGIN:function (para) mylog(接收到 XL_USER_LOGIN数据);jsclient.unblock();if (para) /保存闲聊登录数据到本地var para = para.data;mylog(开始设置本地 XL_USER_LOGIN.);cc.loader.loadTxt(jsb.fileUtils.getWritablePat

44、h() + XLNickName.txt,function (er, txt) if (txt) /重置闲聊昵称para.nickName = escape(txt);/设置大头像信息为“”para.originalAvatar = ;/para.smallAvatar = ;/存储闲聊信息/sys.localStorage.setItem(XL_USER_LOGIN, JSON.stringify(para);jsclient.operateFirstLoginType(xl);/闲聊登录信息初始化xlLoginPara.useSugram = true;xlLoginPara.xl_uni

45、onid =para.openId;xlLoginPara.xl_nickname =para.nickName;xlLoginPara.xl_headimgurl =para.smallAvatar;/闲聊登录mylog(开始进行闲聊登录.);f_login(xlLoginPara););,21.在中_event 内添加 XL_LOGIN_MSG 的事件响应XL_LOGIN_MSG:function (para) if(para.errMsg)switch (para.errMsg)case ERR_SUCCESS:/授权成功jsclient.block();break;case ERR_C

46、ANCEL:/授权登录取消break;case ERR_FAIL:/授权登录失败break;case ERR_UNKNOW:/未知错误break;case ERR_AFTERGETCODE:/获取 code 之后出错jsclient.unblock();break;,22.在中_event 的 WX_USER_LOGIN响应事件内添加WX_USER_LOGIN: function (para) if (para.openid) cc.loader.loadTxt(jsb.fileUtils.getWritablePath() + nickname.txt,function (er, txt)

47、if (txt) para.nickname = escape(txt);/sys.localStorage.setItem(WX_USER_LOGIN, JSON.stringify(para);/jsclient.operateFirstLoginType(wx);/新的写法if(iswxLogin)if(iswxLogin) sssys.localStorage.setItem(WX_USER_LOGIN,sssys.localStorage.setItem(WX_USER_LOGIN,JSON.stringify(para);JSON.stringify(para);jsclient.

48、operateFirstLoginType(wx);jsclient.operateFirstLoginType(wx); LoginAsWeChat(para););,23.在中_event 的 loginRtn 响应事件内添加loginRtn: function (rtn) if (rtn.result = ZJHCode.Success) if (rtn.result = ZJHCode.Success) if (code) cc.sys.localStorage.setItem(loginData, JSON.stringify(loginData);if (code) cc.sys.

49、localStorage.setItem(loginData, JSON.stringify(loginData);var loginType = jsclient.operateFirstLoginType();var loginType = jsclient.operateFirstLoginType();if(loginType = xl)if(loginType = xl)/ mylog(/ mylog(登录成功登录成功 22222222!););var para = ;var para = ;para.openId = xlLoginPara.xl_unionid;para.open

50、Id = xlLoginPara.xl_unionid;para.nickName = xlLoginPara.xl_nickname;para.nickName = xlLoginPara.xl_nickname;para.smallAvatar = xlLoginPara.xl_headimgurl;para.smallAvatar = xlLoginPara.xl_headimgurl;sys.localStorage.setItem(XL_USER_LOGIN, JSON.stringify(para);sys.localStorage.setItem(XL_USER_LOGIN, J

51、SON.stringify(para);. .else if(rtn.result = ZJHCode.needWxRegister)/需要微信登录if (agreeNode.isSelected() if (jsclient.native)iswxLoginiswxLogin = = false;false;jsclient.native.wxLogin();else if(rtn.result = ZJHCode.needWxId)/需要微信 idjsclient.showMsg(微信 id 缺失!)else if(rtn.result = ZJHCode.needXlId)/需要闲聊 i

52、djsclient.showMsg(闲聊 id 缺失!)else if(rtn.result = ZJHCode.bindAnotherWxUser)/闲聊账号绑定了另外的微信idjsclient.showMsg(此微信账号不是您的闲聊账号所绑定的微信账号, 请登录正确的微信账号!)else if(rtn.result = ZJHCode.bindAnotherXlUser)/微信账号绑定了另外的闲聊idjsclient.showMsg(此闲聊账号不是您的微信账号所绑定的闲聊账号, 请登录正确的闲聊账号!)if (unblock)jsclient.unblock();24.在中 ctor 函数

53、内添加xlLoginPara = ;25.在中的 Button_invite的点击事件中添加:Button_invite: _click: function () ./设置闲聊的 parajsclient.xianLiaoPara = ;jsclient.xianLiaoPara.type = XianLiaoType.invite;jsclient.xianLiaoPara.roomId = info.tableid;jsclient.xianLiaoPara.roomToken = gameType:henmj;= jsclient.uiPara.title;jsclient.xianLi

54、aoPara.description = jsclient.uiPara.desc;.,26.在中的邀请按钮的点击事件中添加:wxinvite: ._click: function () ./设置闲聊的 parajsclient.xianLiaoPara = ;jsclient.xianLiaoPara.type = XianLiaoType.invite;jsclient.xianLiaoPara.roomId = tData.tableid;jsclient.xianLiaoPara.roomToken = gameType:henmj;jsclient.xianLiaoPara.titl

55、e = jsclient.uiPara.title;jsclient.xianLiaoPara.description = jsclient.uiPara.desc;.,27.在中添加:var XianLiaoType = text:1,/文本分享image:2, /图片分享invite:3/游戏邀请;jsclient.xianLiaoPara = ;28.在中添加:needWxId: 13,/ 需要微信 idneedXlId: 14,/ 需要闲聊 idbindAnotherWxUser: 15,/ 闲聊账号绑定了另外的微信idbindAnotherXlUser: 16,needWxRegis

56、ter: 17,/ 需要微信注册29.在的 ShareWXLayer中添加一个控件 btn_xianliaobtn_xianliao: _run: function () .,_click: function () jsclient.xlCheckAndShare();30.在的 ShareWXLayer中的_event 添加 XL_USER_LOGINXL_USER_LOGIN:function (para) jsclient.unblock();if(para)/保存闲聊登录数据到本地var para = para.data;cc.loader.loadTxt(jsb.fileUtils.

57、getWritablePath() + XLNickName.txt,function (er, txt) if (txt) /重置闲聊昵称para.nickName = escape(txt);/设置大头像信息为“”para.originalAvatar = ;/para.smallAvatar = ;/存储闲聊信息/sys.localStorage.setItem(XL_USER_LOGIN, JSON.stringify(para);/绑定账号var unionid = jsclient.getWXunionid();jsclient.gamenet.request(pkcon.hand

58、ler.bindSugramUser,unionid: unionid,function (rtn) if(rtn.result = ZJHCode.Success) /存储闲聊信息存储闲聊信息sys.localStorage.setItem(XL_USER_LOGIN,sys.localStorage.setItem(XL_USER_LOGIN, JSON.JSON.stringify(para);stringify(para);jsclient.xlCheckAndShare();else if(rtn.result = ZJHCode.needWxId)/需要微信 idjsclient.

59、showMsg(微信 id 缺失!)else if(rtn.result = ZJHCode.needXlId)/需要闲聊 idjsclient.showMsg(闲聊 id 缺失!)else if(rtn.result = ZJHCode.bindAnotherWxUser)/闲聊账号绑定了另外的微信idjsclient.showMsg(此微信账号不是您的闲聊账号所绑定的微信账号,请登录正确的微信账号!)else if(rtn.result = ZJHCode.bindAnotherXlUser)/微信账号绑定了另外的闲聊idjsclient.showMsg(此闲聊账号不是您的微信账号所绑定的

60、闲聊账号,请登录正确的闲聊账号!););,31.在的 ShareWXLayer中的_event 添加 XL_LOGIN_MSGXL_LOGIN_MSG:function (para) if(para.errMsg)switch (para.errMsg)case ERR_SUCCESS:/授权成功jsclient.block();break;case ERR_CANCEL:/授权登录取消break;case ERR_FAIL:/授权登录失败break;case ERR_UNKNOW:/未知错误break;case ERR_AFTERGETCODE:/获取 code 之后出错jsclient.u

61、nblock();break;,32.在的 ShareWXLayer中的_event 添加 XL_SHARE_MSGXL_SHARE_MSG:function (para) if(para.errMsg)switch (para.errMsg)case ERR_SUCCESS:/分享成功break;case ERR_CANCEL:/分享取消break;case ERR_FAIL:/分享失败break;case ERR_UNKNOW:break;,三、三、IOSIOS 篇篇1.在 xcode 中添加、三个文件2.在中添加#import xlSDK/SugramApiManager.h#impor

62、t xlSDK/SugramApiObject.hNSString * xl_access_token;NSString * xl_refresh_token;NSString * xl_openid;添加位置如下列图:/未知错误3.在中声明变量NSString * XL_AppID = cc93e2b4-4acb-400b-81fe-915ed5d6f7c1;NSString * XL_AppSecret = c8c7ceb3-cd08-40e3-85be-39d0592ed808;NSString * xl_access_token;NSString * xl_refresh_token;

63、NSString * xl_openid;BOOL isAPPNewStart = true;std:string inviateMsgStr = ;4.在中 didFinishLaunchingWithOptions中添加/注册闲聊SugramApiManager registerApp:XL_AppID;/是否为闲聊版本cocos2d:FileUtils:getInstance()-writeStringToFile(control,cocos2d:FileUtils:getInstance()-getWritablePath()+/xianliao.txt);/注册从闲聊跳转过来的游戏调

64、用,注册了以后从Sugram 调起你的游戏 APP 时会以下的 block,如果重复执行这个方法,会执行最后注册的blockSugramApiManager getGameFromSugram:(NSString *roomToken, NSString *roomId, NSNumber *openId) NSString *gameString0 = NSString stringWithFormat:roomToken:%,roomId:%,openId:%, roomToken, roomId, openId;NSString *gameString = NSString string

65、WithFormat:roomToken:%,roomId:%, roomToken, roomId;if(!roomTokenisEqual: & !roomIdisEqual: )if(gameString)dispatch_async(dispatch_get_main_queue(), std:string result_c_str= gameString cStringUsingEncoding: NSUTF8StringEncoding;std:string event =XL_InviteGameInfo;std:string funName =cc.eventManager.d

66、ispatchCustomEvent;std:string rStr = funName + ( + event + , + result_c_str +);if(!isAPPNewStart)NSString *printStr = NSString stringWithCString:rStr.c_str() encoding:NSString defaultCStringEncoding;NSLog(printStr:%,printStr);ScriptingCore:getInstance()-evalString(rStr.c_str();NSLog(已发送闲聊邀请信息(已启动应用)

67、。);elseinviateMsgStr = rStr;NSLog(已保存闲聊邀请信息。););elseNSLog(这里是闲聊内约局(roomToken和 roomId 都是空).);5.在中 handleOpenURL 函数中修改- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url/用户从闲聊调用你的 APP 时,需要从这个方法获得闲聊传递的内容if (SugramApiManager handleOpenURL:url) return YES;/处理微信通过 URL 启动 App 时传递的数据

68、else if(WXApi handleOpenURL:url delegate:self)return YES;elsereturn NO;6.在中 openURL 函数中修改-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation/用户从闲聊调用你的 APP 时,需要从这个方法获得闲聊传递的内容if (SugramApiManager handleOpenURL:u

69、rl) return YES;/处理微信通过 URL 启动 App 时传递的数据else if(WXApi handleOpenURL:url delegate:self)return YES;elsereturn NO;7.在中添加函数 sendXLRequest+(void)sendXLRequestNSLog(闲聊请求 code);if(self isXLInstall)SugramApiManager loginState:sugram_login_state fininshBlock:(SugramLoginCallBackType callBackType,NSString *co

70、de,NSString *state) /获取成功if(callBackType = SugramLoginSuccessType)/根据获取的 code 去获取 tokenNSLog(code:%,code);self getXLToken:code;self xlLoginMSG:callBackType;8.在中添加函数 getXLToken+(void)getXLToken:(NSString* )codeNSLog(根据 code 获取 token);NSString *url = NSString stringWithFormat:/oauth2/accessToken?clien

71、t_id=%&client_secret=%&grant_type=authorization_code&code=%,XL_AppID,XL_AppSecret,code;dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),NSURL *zoneUrl=NSURL URLWithString:url;NSString *zoneStr = NSString stringWithContentsOfURL:zoneUrl encoding:NSUTF8StringEncoding error:n

72、il;NSData *data = zoneStr dataUsingEncoding:NSUTF8StringEncoding;dispatch_async(dispatch_get_main_queue(), if(data)NSDictionary *dic = NSJSONSerialization JSONObjectWithData:dataoptions:NSJSONReadingMutableContainers error:nil;NSInteger xl_code = dic objectForKey:code intValue;if(xl_code = 0)xl_acce

73、ss_token = dic objectForKey:data objectForKey:access_token;xl_refresh_token = dic objectForKey:data objectForKey:refresh_token;/根据 token获取 userinfoself getXLUserinfoByToken;elseself xlErrorAfterGetCode;););9.在中添加函数 getXLUserinfoByToken+(void)getXLUserinfoByTokenNSLog(根据 token去获取 userinfo);NSString *

74、url = NSString stringWithFormat:/resource/user/getUserInfo?access_token=%,xl_access_token;dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),NSURL *zoneUrl=NSURL URLWithString:url;NSString *zoneStr = NSString stringWithContentsOfURL:zoneUrl encoding:NSUTF8StringEncoding erro

75、r:nil;NSData *data = zoneStr dataUsingEncoding:NSUTF8StringEncoding;dispatch_async(dispatch_get_main_queue(), if(data)NSString *result = NSString alloc initWithData:data encoding:NSUTF8StringEncoding;NSDictionary *dic = NSJSONSerialization JSONObjectWithData:dataoptions:NSJSONReadingMutableContainer

76、s error:nil;NSInteger xl_code = dic objectForKey:code intValue;if(xl_code = 0)xl_openid =dic objectForKey:data objectForKey:openId;NSString*nickname = dic objectForKey:data objectForKey:nickName;cocos2d:FileUtils:getInstance()-writeStringToFile(nickname.UTF8String,cocos2d:FileUtils:getInstance()-get

77、WritablePath()+/XLNickName.txt);std:string result_c_str= result cStringUsingEncoding: NSUTF8StringEncoding;std:string event =XL_USER_LOGIN;std:string funName =cc.eventManager.dispatchCustomEvent;std:string rStr = funName + ( + event + , + result_c_str + );NSString *printStr = NSString stringWithCStr

78、ing:rStr.c_str() encoding:NSString defaultCStringEncoding;NSLog(printStr:%,printStr);ScriptingCore:getInstance()-evalString(rStr.c_str();elseself xlErrorAfterGetCode;););10.在中添加函数 xlShareText+(void)xlShareText:(NSString*)title AndText:(NSString*)textNSLog(闲聊分享文本);if(self isXLInstall)SugramShareTextO

79、bject *textObject = SugramShareTextObject alloc init;textObject.title = title;textObject.text = text;SugramApiManager share:textObject fininshBlock:(SugramShareCallBackTypecallBackType) NSLog(callBackType:%ld, (long)callBackType);self xlShareMSG:callBackType;11.在中添加函数 xlShareImage+(void)xlShareImage

80、:(NSString*)pathNSLog(闲聊分享图片);if(self isXLInstall)UIImage *image= UIImage allocinitWithContentsOfFile:path;CGSize size= image size;float scale_1 = 1.0;CGSize scaleSize1 = CGSizeMake(size.width/scale_1,size.height/scale_1);UIGraphicsBeginImageContext(scaleSize1);CGRect rect1 = CGRectMake(0.0, 0.0, sc

81、aleSize1.width, scaleSize1.height);image drawInRect:rect1;UIImage * scaleimage1 = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();float ration_1 = 0.5;SugramShareImageObject *imageObject = SugramShareImageObject alloc init;imageObject.imageData =UIImageJPEGRepresentation(scal

82、eimage1, ration_1);SugramApiManager share:imageObject fininshBlock:(SugramShareCallBackType callBackType) NSLog(callBackType:%ld, (long)callBackType);self xlShareMSG:callBackType;12.在中添加函数 xlShareInvite+(void)xlShareInvite:(NSString*)roomToken AndID:(NSString*)roomId AndTitle:(NSString*)title AndTex

83、t:(NSString*)textNSLog(闲聊分享游戏邀请-roomToken:%roomId:%title:%text:%,roomToken,roomId,title,text);if(self isXLInstall)SugramShareGameObject * inviteObject = SugramShareGameObject alloc init;inviteObject.roomToken = roomToken;inviteObject.roomId = roomId;inviteObject.title = title;inviteObject.text = tex

84、t;inviteObject.imageData =UIImagePNGRepresentation(UIImage imageNamed:Icon-100.png);SugramApiManager share:inviteObject fininshBlock:(SugramShareCallBackTypecallBackType) NSLog(callBackType:%ld, (long)callBackType);self xlShareMSG:callBackType;13.在中添加函数 xlLoginMSG+(void)xlLoginMSG:(SugramLoginCallBa

85、ckType)callBackTypeNSLog(闲聊登录结果.);std:string result_c_str= ;if (callBackType = SugramLoginSuccessType) result_c_str = errMsg:ERR_SUCCESS;else if (callBackType = SugramLoginCancelType) result_c_str = errMsg:ERR_CANCEL;else if(callBackType = SugramLoginErrorType)result_c_str = errMsg:ERR_FAIL;else if(

86、callBackType = SugramLoginUnkonwType)result_c_str = errMsg:ERR_UNKNOW;dispatch_async(dispatch_get_main_queue(), std:string event = XL_LOGIN_MSG;std:string funName = cc.eventManager.dispatchCustomEvent;std:string rStr = funName + ( + event + , + result_c_str + );NSString *printStr = NSString stringWi

87、thCString:rStr.c_str() encoding:NSStringdefaultCStringEncoding;NSLog(printStr:%,printStr);ScriptingCore:getInstance()-evalString(rStr.c_str(););NSLog(闲聊登录结果结束.);14.在中添加函数 xlErrorAfterGetCode+(void)xlErrorAfterGetCodeNSLog(闲聊在获取 code 之后的其他操作失败.);std:string result_c_str = errMsg:ERR_AFTERGETCODE;dispa

88、tch_async(dispatch_get_main_queue(), std:string event = XL_LOGIN_MSG;std:string funName = cc.eventManager.dispatchCustomEvent;std:string rStr = funName + ( + event + , + result_c_str + );NSString *printStr = NSString stringWithCString:rStr.c_str() encoding:NSStringdefaultCStringEncoding;NSLog(printS

89、tr:%,printStr);ScriptingCore:getInstance()-evalString(rStr.c_str(););15.在中添加函数 xlShareMSG+(void)xlShareMSG:(SugramShareCallBackType)callBackTypeNSLog(闲聊分享结果.);std:string result_c_str= ;if (callBackType = SugramShareSuccesslType) result_c_str = errMsg:ERR_SUCCESS;else if(callBackType = SugramShareCan

90、celType)result_c_str = errMsg:ERR_CANCEL;else if(callBackType = SugramShareErrorType)result_c_str = errMsg:ERR_FAIL;else if(callBackType = SugramShareUnkonwType)result_c_str = errMsg:ERR_UNKNOW;dispatch_async(dispatch_get_main_queue(), std:string event = XL_SHARE_MSG;std:string funName = cc.eventMan

91、ager.dispatchCustomEvent;std:string rStr = funName + ( + event + , + result_c_str + );NSString *printStr = NSString stringWithCString:rStr.c_str() encoding:NSStringdefaultCStringEncoding;NSLog(printStr:%,printStr);ScriptingCore:getInstance()-evalString(rStr.c_str(););NSLog(闲聊分享结果结束.);16.在中添加函数 xlGet

92、InviteGameInfo+(void)xlGetInviteGameInfoNSLog(查询闲聊查询游戏邀请信息.);NSString *inviateMsgStr1 = NSString stringWithCString:inviateMsgStr.c_str() encoding:NSString defaultCStringEncoding;NSLog(inviateMsgStr:%len=%lu,inviateMsgStr1,inviateMsgStr.length();if(inviateMsgStr.length() 0)dispatch_async(dispatch_get

93、_main_queue(), NSLog(准备发送闲聊邀请信息.);ScriptingCore:getInstance()-evalString(inviateMsgStr.c_str();NSLog(已发送闲聊邀请信息(新启动应用)。);inviateMsgStr = ;NSLog(已重置闲聊邀请信息。););17.在中添加函数 isXLInstall+(BOOL)isXLInstallBOOL haveXL = SugramApiManager isInstallSugram;if(haveXL)NSLog(have xianliao app);return true;elseNSLog(

94、no xianliao app);self doWithoutXLApp;return false;18.在中添加函数 doWithoutXLApp+(void)doWithoutXLAppNSLog(doWithoutXLApp.);19.在中的函数 applicationDidEnterBackground中添加isAPPNewStart = false;20.在中的函数 applicationWillEnterForeground中添加isAPPNewStart = false;21.在中添加LSApplicationQueriesSchemesxianliaoCFBundleTypeRoleEditorCFBundleURLNamexianliaoCFBundleURLSchemesxianliaocc93e2b4-4acb-400b-81fe-915ed5d6f7c1

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号