dezhou_client/lua_probject/base_project/Game/View/Lobby/WeChatView.lua

79 lines
2.0 KiB
Lua
Raw Permalink Normal View History

2025-12-17 21:08:27 +08:00
-- 同步微信信息
local WeChatView = {}
local M = WeChatView
function WeChatView.new(callback)
setmetatable(M, {__index = BaseWindow})
local self = setmetatable({}, {__index = M})
self.class = "WeChatView"
self._close_destroy = true
self._close_zone = true
self._callback =callback
self:init("ui://Lobby/win_user_wx")
return self
end
function M:init(url)
BaseWindow.init(self,url)
local btn_ok = self._view:GetChild("btn_ok")
btn_ok.onClick:Set(function ()
ViewUtil.ShowModalWait(self._root_view,"正在同步数据...")
GameApplication.Instance:WXLogin(handler(self,self.WXCallBack))
end)
end
function M:WXCallBack(result,data)
if (not result) or result ~= 0 then
if result == 10 then
ViewUtil.ShowModalWait(self._root_view)
return
end
ViewUtil.CloseModalWait()
return
end
if not data then
ViewUtil.CloseModalWait()
return
end
local jd = json.decode(data)
local headurl = jd["headimgurl"]
local unionid = jd["unionid"]
local sex = jd["sex"]
if (sex == 0) then sex = 1 end
local nickname = jd["nickname"]
if not unionid or string.len(unionid)<1 then
ViewUtil.CloseModalWait()
return
end
local _data = {}
_data.type =6
_data["acc"] = unionid
_data["nick"] = nickname
_data["sex"] = sex
_data["portrait"] = headurl
local loddyctr = ControllerManager.GetController(LoddyController)
loddyctr:UpdateUserInfo(_data,function( res)
ViewUtil.CloseModalWait()
if (res.ReturnCode ==0) then
local user = DataManager.SelfUser
user.acc = unionid
user.nick_name = nickname
user.sex = sex
user.head_url = headurl
if self._callback then self._callback() end
else
ViewUtil.ErrorTip(res.ReturnCode, "同步失败,请重试")
end
self:Close()
end)
end
return M