当前位置:网站首页>Lua wechat avatar URL
Lua wechat avatar URL
2022-07-05 04:56:00 【Meteor spot】
function App.createHeadSprite(url,userID)
local name = md5.sumhexa(url)
local headPicName = name..".png"
local filepath = cc.FileUtils:getInstance():getWritablePath()
filepath = filepath.."UserFaceImage"
local imgFile = filepath.."/"..headPicName
if App.fileExist(imgFile) then
ls.TextureCache:removeTextureForKey(imgFile)
ls.TextureCache:addImage(imgFile)
return;
end
if url ~= nil and string.len(url) > 0 then
App.downHeadByUrl(url,userID,updateHeadImage)
end
end
-- Download the avatar
function App.downHeadByUrl(url,userID)
if url == nil then
return
end
-- Store names
local name = md5.sumhexa(url)
local headPicName = name..".png"
-- Storage path
local filepath = cc.FileUtils:getInstance():getWritablePath()
filepath = filepath.."UserFaceImage"
ls.FileUtils:createDirectory(filepath)
--end
-- Downloaded avatar pictures
local imgFile = filepath.."/"..headPicName
local xhr = cc.XMLHttpRequest:new()
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER
xhr:open("GET",url)
local function OnDownLoadFinish()
if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then
local fileData = xhr.response
local size = table.getn(fileData)
if size > 100 then
--os.remove(imgFile)
local file = io.open(imgFile,"wb")
if file==nil then
return
end
for i = 1,size do
file:write(string.char(fileData[i]))
end
file:close()
end
--local texture = ls.TextureCache:addImage(imgFile)
ls.TextureCache:addImage(imgFile)
ls.dispatchCustomEvent(App.Event.updataWXHead, userID)
xhr:unregisterScriptHandler()
end
end
xhr:registerScriptHandler(OnDownLoadFinish)
xhr:send()
end
---------------------
-- Get avatar texture
function App.getUserFaceImage(userID , url)
-- Store names
local name = md5.sumhexa(url)
local headPicName = name..".png"
-- Storage path
local filepath = cc.FileUtils:getInstance():getWritablePath()
filepath = filepath.."UserFaceImage"
--end
-- Downloaded avatar pictures
local imgFile = filepath.."/"..headPicName
local texture = ls.TextureCache:getTextureForKey(imgFile)
if not texture then
local pTemp = cc.Sprite:create("lobby_female_face.png")
texture = pTemp:getTexture()
end
return texture
end
---------------------
-- Judge whether the file exists
function App.fileExist(path)
if path == nil then
return false
end
local file = io.open(path,"rb")
if file ~= nil then
file:close()
return true
end
return false
end
---------------------
边栏推荐
- 2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
- 猿人学第一题
- Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
- UE 虚幻引擎,项目结构
- Personal required code
- Database under unity
- AutoCAD - command repetition, undo and redo
- "Measuring curve length" of CAD dream drawing
- Solution of circular dependency
- 【acwing】836. Merge sets
猜你喜欢
![[groovy] closure (closure as function parameter | code example)](/img/a6/a4ed401acfb61f85eb08daa15a8a80.jpg)
[groovy] closure (closure as function parameter | code example)
![[groovy] closure (closure call | closure default parameter it | code example)](/img/61/754cee9a940fd4ecd446b38c2f413d.jpg)
[groovy] closure (closure call | closure default parameter it | code example)

Thinking of 2022 American College Students' mathematical modeling competition

AutoCAD - scaling

Unity check whether the two objects have obstacles by ray

Manually implement heap sorting -838 Heap sort

3dsmax snaps to frozen objects

質量體系建設之路的分分合合

Unity parallax infinite scrolling background

Emlog blog theme template source code simple good-looking responsive
随机推荐
Unity intelligent NPC production -- pre judgment walking (method 1)
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
Unity sends messages and blocks indecent words
中国AS树脂市场调研与投资预测报告(2022版)
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
AutoCAD - command repetition, undo and redo
Unity get component
Special information | real estate and office buildings - 22.1.9
AutoCAD - feature matching
Unity connects to the database
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
Detailed introduction of OSPF header message
质量体系建设之路的分分合合
【acwing】836. Merge sets
2021-10-29
AutoCAD - isometric annotation
数论函数及其求和 待更新
【Leetcode】1352. Product of the last K numbers
中国金刚烷行业研究与投资预测报告(2022版)
stm32Cubemx(8):RTC和RTC唤醒中断