cocos2dx整合友盟社會化分享
阿新 • • 發佈:2019-01-01
appid對了 , key也對了,為什麼就是分享不成功呢,我日!
找了2天,發現,尼瑪,原來CCApp.java裡面也有做設定平臺資訊的配置, 原來這裡的appid appkey 不對。 改了這裡,就分享成功了。日。
public class CCApp extends Application{ { PlatformConfig.setWeixin("wx4111c4b9d895d423", "20d56bf6cf8a11a40f4adafa6929f484"); PlatformConfig.setSinaWeibo("3921700954","04b48b094faeb16683c32669824ebdad"); PlatformConfig.setYixin("yxc0614e80c9304c11b0391514d09f13bf"); PlatformConfig.setLaiwang("laiwangd497e70d4", "d497e70d4c3e4efeab1381476bac4c5e"); PlatformConfig.setQQZone("100424461", "c7394704798a158208a74ab30104f0ba"); PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi", "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO"); } }
#include "stdafx.h" #include "LuaMgr.h" #include "CustomNode.h" #include "LuaCsbLoader.h" #include "Cocos2dx/Common/CCUMSocialSDK.h" #include "Cocos2dx/ShareButton/UMShareButton.h" #include "LuaUMengShare.h" USING_NS_CC; // ʹ???????????ռ? USING_NS_UM_SOCIAL; #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) /* * ?????ص?, ?ûص?????ij?????ij?Ա?????? ????һ????ͨ?ĺ???, ????ʹ?òο?HelloWorldScene?????? * @param platform Ҫ????????Ŀ??ƽ̨ * @param stCode ??????, 200?????????ɹ?, 100??????ʼ???? * @param errorMsg ????ʧ??ʱ?Ĵ?????Ϣ,androidƽ̨û?д?????Ϣ */ void shareCallback(int platform, int stCode, string& errorMsg) { if ( stCode == 100 ) { XLOG("####111111111111111111111111111111111111111 ??ʼ???? %d.", stCode); } else if ( stCode == 200 ) { XLOG("####2222222222222222222222222222222222222222 ?????ɹ? %d.", stCode); } else { XLOG("####333333333333333333333333333333333333333333 ???????? %d.", stCode); } XLOG("############################################platform num is : %d.", platform); } IMPL_LUA_CLASS_BEGIN(LuaUMengShare) EXPORT_LUA_FUNCTION(LuaAddUMengShare) IMPL_LUA_CLASS_END() int LuaUMengShare::LuaAddUMengShare(lua_State* L) { //const char* url = luaL_checkstring(L, 1); if (init()) return 0; else return 1; } bool LuaUMengShare::init() { if ( !CCLayer::init() ) { return false; } // ??????????ť, ????1Ϊ??ť?????????µ?ͼƬ, ????2Ϊ??ťѡ??ʱ??ͼƬ,????3Ϊ????appkey, ????4Ϊ?????ص? UMShareButton *shareButton = UMShareButton::create("img/mole/weixin.png","img/mole/weixin.png", "56f8da28e0f************e3", share_selector(shareCallback)); // ??ʾ?????˷????????ϵ?ƽ̨ vector<int>* platforms = new vector<int>(); // platforms->push_back(SINA); // platforms->push_back(RENREN); // platforms->push_back(DOUBAN); platforms->push_back(QZONE); platforms->push_back(QQ); platforms->push_back(WEIXIN); platforms->push_back(WEIXIN_CIRCLE); // ???????˷???????????ʾ??ƽ̨ shareButton->setPlatforms(platforms); // ?????ı????????? shareButton->setShareContent("umeng social cocos2d-x sdk.") ; // ????Ҫ??????ͼƬ, ͼƬ֧?ֱ???ͼƬ??urlͼƬ, ????urlͼƬ??????http://????https://??ͷ //shareButton->setShareImage("img/mole/weixin.png") ; // ???ð?ť??λ?? shareButton->setPosition(ccp(150, 180));
CCMenu* pMenu = CCMenu::create(shareButton, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); // ********************** ????ƽ̨??Ϣ *************************** CCUMSocialSDK *sdk = shareButton->getSocialSDK(); sdk->setQQAppIdAndAppKey("11052*6505", "ErGT3*VLqxgaOjQ3"); sdk->setWeiXinAppInfo("wx4111c4b9****5d429", "20d56bf*****a11a40f4adafa6929f482"); // ?????û?????һ??ͼ?ķ???ʱ?û???ת????Ŀ??ҳ??, һ??Ϊapp??ҳ????????ҳ?? // -- 注意, 這個檔案要用utf-8的格式開啟哦,否則中文分享會亂碼,甚至導致遊戲閃退! sdk->setPlatformShareContent(QQ, "換實物獎品哦~~", "http://c.csdnimg.cn/www/images/ali.png", "無聊?吧~", "http://www.cocos.com/"); sdk->setPlatformShareContent(QZONE, "兌換實物獎品哦~~", "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png", "無聊?~", "http://www.cocos.com/"); sdk->setPlatformShareContent(WEIXIN, "實物獎品哦~~", "http://c.csdnimg.cn/www/images/ali.png", "無聊?~", "http://www.cocos.com/"); sdk->setPlatformShareContent(WEIXIN_CIRCLE, "實物獎品哦~~", "http://c.csdnimg.cn/www/images/ali.png", "無聊?~", "http://www.cocos.com/"); // ?