当前位置:网站首页>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
---------------------
边栏推荐
- 775 Div.1 B. integral array mathematics
- 54. Spiral matrix & 59 Spiral matrix II ●●
- Redis has four methods for checking big keys, which are necessary for optimization
- LeetCode之单词搜索(回溯法求解)
- AutoCAD - graphic input and output
- Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
- [groovy] closure (Introduction to closure class closure | this, owner, delegate member assignment and source code analysis)
- Unity parallax infinite scrolling background
- Common technologies of unity
- #775 Div.1 C. Tyler and Strings 组合数学
猜你喜欢

Detailed introduction of OSPF header message

XSS injection
![[groovy] closure (closure call | closure default parameter it | code example)](/img/61/754cee9a940fd4ecd446b38c2f413d.jpg)
[groovy] closure (closure call | closure default parameter it | code example)

Recherche de mots pour leetcode (solution rétrospective)

Emlog blog theme template source code simple good-looking responsive

AutoCAD - workspace settings
![[goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens](/img/20/5c5550e6dabc76702f0e7ce3bef068.jpg)
[goweb development] Introduction to authentication modes based on cookies, sessions and JWT tokens

3dsmax scanning function point connection drawing connection line
![Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]](/img/e7/f699ee982ea325b8d04f8bd467a559.jpg)
Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]

AutoCAD - window zoom
随机推荐
Interface joint commissioning test script optimization V5.0 (end)
Special information | finance, accounting, audit - 22.1.23
中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
JMeter -- distributed pressure measurement
Judge the position of the monster in the role under unity3d
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
Unity connects to the database
Recherche de mots pour leetcode (solution rétrospective)
The difference between bundle, chunk and module
PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
669. Prune binary search tree ●●
#775 Div.1 C. Tyler and Strings 组合数学
Create a pyGame window with a blue background
Emlog blog theme template source code simple good-looking responsive
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
[groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)
MySQL audit log archiving
Wan broadband access technology V EPON Technology
3dsmax common commands
Basic knowledge points