def wx_get_user_info(code: str, encryptedData: str, iv: str): appid = config.get("wx", {}).get("appid", "") secret = config.get("wx", {}).get("appsecret", "") # 通过code获取用户信息 res = requests.get( f"https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={secret}&js_code={code}&grant_type=authorization_code" ).json() session_key = res["session_key"] pc = WXBizDataCrypt(appid, session_key) data = pc.decrypt(encryptedData, iv) # {'openId': 'okQcr5BeEQN02Etgyhem5gje1RK8', 'nickName': '瘦瘦要变成瘦瘦', 'gender': 1, 'language': 'zh_CN', # 'city': 'Chaoyang', 'province': 'Beijing', 'country': 'China', # 'avatarUrl': 'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIXC2byoG7GJKdYVLvEWibbAI9tjcMmy5whWkjgBH52K4wECTdv4Hc4zNKR6MK9NGic5Qia0ICh8Nd0Q/132', # 'watermark': {'timestamp': 1583553168, 'appid': 'wx01583ccc3e25c0be'}} return data
def create_app(): flask_app = Flask(__name__) flask_app.config = dict(flask_app.config, **config.get('system')) CORS(flask_app, supports_credentials=True) # setup_plugins.install_blueprint(flask_app) configure_extensions(flask_app) register_blueprints(flask_app) flask_app.json_encoder = DecimalEncoder write_pid.run() return flask_app
from arrplat.common.utils import json_response from arrplat.config import config from qiniu import Auth, put_data from flask_restful import Resource from flask import request import uuid Conf = config.get('qiniu') class FileUpload(Resource): def post(self, bucket_name='', image_name_to_uuid_handle=True): """图片上传接口 --- parameters: - name: bucket_name in: url type: string required: true description: 篮子名称 - name: file in: body type: byte required: true description: 图片二进制文件 responses: 200: examples: response: {"data": null, "message": "修改成功"} """
# -*- coding: utf-8 -*- import json import uuid import random from aliyunsdkdysmsapi.request.v20170525 import SendSmsRequest from aliyunsdkcore.client import AcsClient from aliyunsdkcore.profile import region_provider from arrplat.config import config Conf = config.get('message') acs_client = AcsClient(Conf.get('ACCESS_KEY_ID'), Conf.get('ACCESS_KEY_SECRET'), Conf.get('REGION')) region_provider.modify_point(Conf.get('PRODUCT_NAME'), Conf.get('REGION'), Conf.get('DOMAIN')) def send_sms(business_id, phone_numbers, sign_name, template_code, template_param=None): sms_request = SendSmsRequest.SendSmsRequest() sms_request.set_TemplateCode(template_code) if template_param is not None: sms_request.set_TemplateParam(template_param) sms_request.set_OutId(business_id) sms_request.set_SignName(sign_name) sms_request.set_PhoneNumbers(phone_numbers) sms_response = acs_client.do_action_with_exception(sms_request) return sms_response
from redis import StrictRedis from arrplat.config import config class DBUtils(object): # redis @staticmethod def get_redis_client(redis_config): return StrictRedis(redis_config['host'], redis_config['port'], redis_config['db'], redis_config['password']) redis_0 = DBUtils.get_redis_client(config.get('redis'))
import random from io import BytesIO from PIL import Image from PIL import ImageDraw from PIL import ImageFont from arrplat.config import config FONT_PATH = config.get("system", dict()).get("FONT_PATH") if not FONT_PATH: raise Exception("Place config font path!") class VerifyCodeImg: def __init__(self, width=150, height=30, code_count=4, font_size=35, point_count=0, line_count=0, img_format='png', font_path=FONT_PATH): self.width = width self.height = height self.code_count = code_count self.font_size = font_size self.point_count = point_count self.line_count = line_count self.img_format = img_format
import logging from arrplat.config import config import os from functools import partial API_CONFIG = os.environ.get('API_CONFIG', 'development') Conf = config.get('system') class EnvLogger: """ example: env_logger = EnvLogger(__name__).env_getlogger() env_logger.info('foo') """ def __init__(self, env_name, mod_name): self.env_name = env_name self.mod_name = mod_name @staticmethod def _getlogger(mod_name: str, file_path: str = "", log_level=logging.INFO, handler_level=logging.INFO, is_print=True): logger = logging.getLogger(mod_name) logger.setLevel(log_level) logger.propagate = False if is_print: handler = logging.StreamHandler() else: