当前位置:网站首页>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
---------------------
边栏推荐
- Thinking of 2022 American College Students' mathematical modeling competition
- China polyurethane rigid foam Market Research and investment forecast report (2022 Edition)
- AutoCAD - stretching
- Flink集群配置
- This article is good
- AutoCAD - command repetition, undo and redo
- Unity sends messages and blocks indecent words
- xss注入
- mysql審計日志歸檔
- Introduce Hamming distance and calculation examples
猜你喜欢

2022 U.S. college students' mathematical modeling e problem ideas / 2022 U.S. game e problem analysis

Solution of circular dependency

Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation

AutoCAD - graphic input and output

SQL set operation

Autocad-- Real Time zoom

AutoCAD - Document Management

2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling

UE 虚幻引擎,项目结构

JVM 原理和流程简介
随机推荐
SQL set operation
2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
Redis has four methods for checking big keys, which are necessary for optimization
[groovy] closure (closure call | closure default parameter it | code example)
2022 thinking of mathematical modeling D problem of American college students / analysis of 2022 American competition D problem
Sqlserver stored procedures pass array parameters
PR first time
stm32Cubemx(8):RTC和RTC唤醒中断
GameObject class and transform class of unity
Looking at Chinese science and technology from the Winter Olympics: what is the mystery of the high-speed camera that the whole people thank?
Solution of circular dependency
LeetCode之单词搜索(回溯法求解)
【Leetcode】1352. Product of the last K numbers
Emlog博客主题模板源码简约好看响应式
Autocad-- dynamic zoom
Download the details and sequence of the original data access from the ENA database in EBI
Unity writes timetables (without UI)
django连接数据库报错,这是什么原因
China as resin Market Research and investment forecast report (2022 Edition)
Pdf to DWG in CAD