当前位置:网站首页>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
---------------------
边栏推荐
- AutoCAD - feature matching
- Unity intelligent NPC production -- pre judgment walking (method 1)
- Error statuslogger log4j2 could not find a logging implementation
- [Chongqing Guangdong education] National Open University 2047t commercial bank operation and management reference test in autumn 2018
- Sixth note
- AutoCAD - scaling
- JVM 原理和流程简介
- 3dsmax scanning function point connection drawing connection line
- The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
- PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
猜你喜欢
Wan broadband access technology V EPON Technology
669. Prune binary search tree ●●
AutoCAD -- dimension break
Emlog博客主题模板源码简约好看响应式
PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
How to choose a panoramic camera that suits you?
Pdf to DWG in CAD
LeetCode之單詞搜索(回溯法求解)
2021-10-29
AutoCAD - graphic input and output
随机推荐
Research and investment forecast report of adamantane industry in China (2022 Edition)
【acwing】240. food chain
3dsmax snaps to frozen objects
Redis 排查大 key 的4种方法,优化必备
Wan broadband access technology V EPON Technology
2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
stm32Cubemx(8):RTC和RTC唤醒中断
Error statuslogger log4j2 could not find a logging implementation
【Leetcode】1352. Product of the last K numbers
C # perspective following
AutoCAD - scaling
LeetCode之單詞搜索(回溯法求解)
This article is good
PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
用 Jmeter 工具做个小型压力测试
2022 thinking of Mathematical Modeling B problem of American college students / analysis of 2022 American competition B problem
PR first time
质量体系建设之路的分分合合
Sixth note
Use assimp library to read MTL file data