微信分享,用的是lua写的,代码如下:
local MainScene = class(“MainScene”, cc.load(“mvc”).ViewBase)
local btnAction
local share_plugin = nil
function MainScene:onCreate()
local appKey = “FB769374-0ACD-61B0-C7B2-D1DDEBD6CC11”
local appSecret = “1e4599dbcf40da0e4d81a944440311e0”
local privateKey = “E5107E9C2207AFE914AB7500E8445650”
local oauthLoginServer = “http://oauth.anysdk.com/api/OauthLoginDemo/Login.php”
local agent = AgentManager:getInstance()
–init
agent:init(appKey,appSecret,privateKey,oauthLoginServer)
–load
agent:loadAllPlugins()
local function onShareResult(code, msg)
print("on share result listener.")
print("code:"..code..",msg:"..msg)
if code == ShareResultCode.kShareSuccess then
--do
elseif code == ShareResultCode.kShareFail then
--do
elseif code == ShareResultCode.kShareCancel then
--do
elseif code == ShareResultCode.kShareNetworkError then
--do
end
end
share_plugin = agent:getSharePlugin()
share_plugin:setResultListener(onShareResult)
-- add background image
display.newSprite("HelloWorld.png")
:move(display.center)
:addTo(self)
-- add HelloWorld label
cc.Label:createWithSystemFont("Hello World", "Arial", 40)
:move(display.cx, display.cy + 200)
:addTo(self)
ccui.Button:create("button_01.png", "button_01.png", "button_01.png", 0)
:move(display.cx + 100, display.cy)
:addTo(self)
:onTouch(btnAction)
end
btnAction = function (event)
if(event.name == “began”)then
print(“999999”)
local info = {
title = “微信分享”, --title 标题,印象笔记、邮箱、信息、微信、人人网和 QQ 空间使用
imagePath = “card.png”, --imagePath 是图片的本地路径,Linked-In 以外的平台都支持此参数
url = “http://sharesdk.cn”, --url 仅在微信(包括好友和朋友圈)中使用
text = “ShareSDK 集成了简单、支持如微信、新浪微博、腾讯微博等社交平台”, --text 是分享文本,所有平台都需要这个字段
mediaType = “1”, --微信 SDK 需要是用到的参数,分享类型: 0 - 文字 1 - 图片 2 - 网址
shareTo = “0”, --微信 SDK 需要是用到的参数,分享到:0 - 聊天 1 - 朋友圈 2 - 收藏
thumbImage = “card.png”,
}
share_plugin:share(info)
end
end
return MainScene