当前位置:网站首页>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
---------------------
边栏推荐
- Wan broadband access technology V EPON Technology
- JVM 原理和流程简介
- [ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
- Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]
- LeetCode之單詞搜索(回溯法求解)
- 2020-10-27
- Sixth note
- UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
- MySQL audit log Archive
- Create a pyGame window with a blue background
猜你喜欢
质量体系建设之路的分分合合
UE 虚幻引擎,项目结构
XSS injection
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
Create a pyGame window with a blue background
SQL set operation
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
AutoCAD - stretching
AutoCAD - command repetition, undo and redo
Solutions and answers for the 2021 Shenzhen cup
随机推荐
This article is good
LeetCode之单词搜索(回溯法求解)
JVM 原理和流程简介
Unity sends messages and blocks indecent words
Create a pyGame window with a blue background
Unity parallax infinite scrolling background
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
Looking at Chinese science and technology from the Winter Olympics: what is the mystery of the high-speed camera that the whole people thank?
Redis 排查大 key 的4种方法,优化必备
On-off and on-off of quality system construction
54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
Unity synergy
【acwing】836. Merge sets
2021 huashubei mathematical modeling idea + reference + paper
The first topic of ape Anthropology
Flink集群配置
Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
AutoCAD - workspace settings
次小生成树
Establish cloth effect in 10 seconds