26 lines
779 B
Python
26 lines
779 B
Python
import oss2
|
|
import re
|
|
|
|
oss_ak = 'LTAI5tC2qXGxwHZUZP7DoD1A'
|
|
oss_sk = 'qPo9O6ZvEfqo4t8oflGEm0DoxLHJhm'
|
|
|
|
def oss_get_object(endpoint, bucket_name, key):
|
|
auth = oss2.Auth(oss_ak, oss_sk)
|
|
bucket = oss2.Bucket(auth, endpoint, bucket_name)
|
|
return bucket.get_object(key)
|
|
|
|
def oss_put_object(endpoint, bucket_name, key, data):
|
|
auth = oss2.Auth(oss_ak, oss_sk)
|
|
bucket = oss2.Bucket(auth, endpoint, bucket_name)
|
|
bucket.put_object(key, data)
|
|
|
|
def get_qr_image_bytes(qr_code):
|
|
code_re = re.compile(r'[0-9]{6,}')
|
|
m = code_re.search(qr_code)
|
|
if not m:
|
|
return None
|
|
code = m.group(0)
|
|
prefix = code[:2]
|
|
key = f'v5/{prefix}/{code}.jpg'
|
|
obj = oss_get_object('https://oss-cn-guangzhou.aliyuncs.com', 'emblem-qrs', key)
|
|
return obj.read() |