如题 编写了代码url形式的 但是发到群里居然是表情包类 无法放大查看细节 各位大神有解决办法么 或者更加优化方案
import requests
import time
import hmac
import hashlib
import base64
import oss2
# 阿里云OSS相关配置
access_key_id = 'ZZ'
access_key_secret = 'ZZ'
endpoint = 'oss-rg-china-mainland.aliyuncs.com'
bucket_name = 'tan'
# 初始化OSS客户端
auth = oss2.Auth(access_key_id, access_key_secret)
bucket = oss2.Bucket(auth, endpoint, bucket_name)
image_formats = ('.png', '.jpg', '.jpeg', '.gif', '.bmp')
for obj in oss2.ObjectIterator(bucket):
bucket.batch_delete_objects([obj.key])
print("All files deleted from the bucket.")
print("Bucket中的所有文件已删除。")
# 上传图片到阿里云盘
local_file_path = r'C:\Users\admin\Desktop\temp\temp.png'
remote_file_name = 'example.jpg'
bucket.put_object_from_file(remote_file_name, local_file_path)
# 获取上传图片的URL
url = bucket.sign_url('GET', remote_file_name, 60) # URL有效期为3600秒
print("Uploaded image URL:", url)
def send_image_to_dingtalk_group(image_url, webhook_url, secret):
timestamp = str(round(time.time() * 1000))
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
sign = hmac.new(secret_enc, string_to_sign.encode('utf-8'), hashlib.sha256).digest()
sign = base64.b64encode(sign)
headers = {
'Content-Type': 'application/json',
}
payload = {
"msgtype": "image",
"image": {
"picURL": image_url
}
}
params = {
'timestamp': timestamp,
'sign': sign.decode('utf-8')
}
response = requests.post(webhook_url, headers=headers, params=params, json=payload)
if response.status_code == 200:
print("Image sent to DingTalk group successfully!")
else:
print("Failed to send image to DingTalk group. Status code: ", response.status_code)
# Replace with your actual webhook URL, image URL and secret
webhook_url = "https://oapi.dingtalk.com/robot/send?access_token=XX"
image_url =bucket.sign_url('GET', remote_file_name, 60)
secret = "SEC"
send_image_to_dingtalk_group(image_url, webhook_url, secret)