中国本土应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6KB

  1. # -*- coding: utf-8 -*-
  2. from odoo import api, models, tools, _
  3. import base64
  4. import requests
  5. import io
  6. import os
  7. import platform
  8. import logging
  9. from odoo.modules.module import get_module_resource
  10. _logger = logging.getLogger(__name__)
  11. class WecomApiToolsFile(models.AbstractModel):
  12. _name = "wecomapi.tools.file"
  13. _description = "Wecom API Tools - File"
  14. def path_is_exists(self, path, subpath):
  15. """
  16. 检文件夹路径是否存在,不存在则创建路径
  17. return:返回路径
  18. """
  19. if platform.system() == "Windows":
  20. filepath = path.replace("\\", "/") + subpath + "/"
  21. else:
  22. filepath = path + subpath + "/"
  23. # print(filepath)
  24. if not os.path.exists(filepath):
  25. os.makedirs(filepath)
  26. return filepath
  27. def get_avatar_base64(self, use_default_avatar, gender, avatar_url):
  28. """
  29. 获取企业微信用户头像的base64编码
  30. return:返回base64
  31. """
  32. imgbase64 = ""
  33. if use_default_avatar or avatar_url == "":
  34. image_name = "default_image.png"
  35. if gender == "1":
  36. image_name = "default_male_image.png"
  37. elif gender == "2":
  38. image_name = "default_female_image.png"
  39. default_image = get_module_resource("hrms_base", "static/src/img", image_name)
  40. # print(default_image)
  41. with open(default_image, "rb") as f:
  42. imgbase64 = base64.b64encode(f.read())
  43. else:
  44. imgbase64 = base64.b64encode(requests.get(avatar_url).content)
  45. return imgbase64
上海开阖软件有限公司 沪ICP备12045867号-1