49 lines
2.4 KiB
Python
49 lines
2.4 KiB
Python
import json
|
|||
|
|
|
||
|
|
import requests
|
||
|
|
from pydantic import BaseModel, Field
|
||
|
|
|
||
|
|
from wechat_token.token工具包 import sixToken
|
||
|
|
|
||
|
|
|
||
|
|
class mini用工关系管理工具包(BaseModel):
|
||
|
|
# demo_必填: int = Field(..., description="描述") # 必传属发生
|
||
|
|
# demo_可选: Optional[int] = None # 可选值
|
||
|
|
# demo_默认值: int = Field(default=100001, description="描述") # 有默认值
|
||
|
|
# demo_联合类型: Literal["xiao", "zizi"] = Field(..., description="描述")
|
||
|
|
tmplIds: int = Field(default="SFFgGF1bN56_KNd_4HicCFBBfu2PCRwCyQ5upr-EVk9Vdyl4wyyQ7B1mJvjceR29", description="绑定的模板ID账号")
|
||
|
|
|
||
|
|
def sendMini给绑定员工推送服务消息(self, touser_推送用户的openid: str):
|
||
|
|
mini_token = sixToken.get_mini_token()
|
||
|
|
|
||
|
|
template_content = {
|
||
|
|
"data": { # ⚠️ 这个外层 "data" 是微信接口强制要求的嵌套结构
|
||
|
|
"thing1": {"value": "aaaaaaa"}, # 替换为模板实际字段名
|
||
|
|
"amount1": {"value": "12"}, # 金额建议纯数字(无¥符号)
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
# 2. 转为JSON字符串(ensure_ascii=False保留中文,但微信要求最终是转义后的字符串)
|
||
|
|
data_string = json.dumps(template_content, ensure_ascii=False)
|
||
|
|
|
||
|
|
msgData = requests.post(url="https://api.weixin.qq.com/cgi-bin/message/wxopen/employeerelationmsg/send",
|
||
|
|
params={"access_token": mini_token, },
|
||
|
|
json={"template_id": "SFFgGF1bN56_KNd_4HicCFBBfu2PCRwCyQ5upr-EVk9Vdyl4wyyQ7B1mJvjceR29", # 推送消息模板
|
||
|
|
"page": "pageTabBar/Home/Home", # 跳转路径
|
||
|
|
"touser": touser_推送用户的openid, # 被推送用户openid
|
||
|
|
"data": data_string,
|
||
|
|
})
|
||
|
|
print(msgData.json())
|
||
|
|
|
||
|
|
def 解绑用工关系(self, touser_推送用户的openid):
|
||
|
|
""""""
|
||
|
|
mini_token = sixToken.get_mini_token()
|
||
|
|
infoData = requests.post(url="https://api.weixin.qq.com/wxa/business/unbinduserb2cauthinfo", params={"access_token": mini_token, }, json={"openid_list": [touser_推送用户的openid]}, )
|
||
|
|
print(infoData.json())
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
pass
|
||
|
|
# mini用工关系管理工具包().sendMini给绑定员工推送服务消息(touser_推送用户的openid="ohQkD7NJ5EASxdh6ajad4QR_6i78")
|
||
|
|
mini用工关系管理工具包().解绑用工关系(touser_推送用户的openid="ohQkD7NJ5EASxdh6ajad4QR_6i78")
|