Comments (2)
大佬能更详细一些么。。
from wechat-public-account-push.
大佬能更详细一些么。。
现在的问题是存在可显示字符的数量限制,一次可能只能显示大概19个字符?
因此考虑解决方案就是:我将长字符串拆分成多个短字符串(比如单个短字符串19个字符),然后将它们组成一个字典传输,然后再将这些内容拼接起来就好了。
具体使用方式就是将下面代码插入到你python获取星座运势或者其他长文本内容之后:
...... (代码省略) # 调用获取星座运势的函数 horoscope = get_horoscope(config) #print(note_ch) #print(note_en) print(horoscope) # 星座运势处理代码 s1 = horoscope['horoscope1'] s2 = horoscope['horoscope2'] r1 = [] r2 = [] maxLen = 19 maxList = 6 for i in range(len(s1)): if i % maxLen == 0 and i != 0: r1.append(s1[i-maxLen : i]) t = len(s1) % maxLen r1.append(s1[len(s1)-t:]) if len(r1) < maxList: for i in range(maxList - len(r1)): r1.append('') horoscope['horoscope1'] = r1 for i in range(len(s2)): if i % maxLen == 0 and i != 0: r2.append(s2[i-maxLen : i]) t = len(s2) % maxLen r2.append(s2[len(s2)-t:]) if len(r2) < maxList: for i in range(maxList - len(r2)): r2.append('') horoscope['horoscope2'] = r2 print(horoscope) # 公众号推送消息 for user in users: send_message(user, accessToken, city, weather, max_temperature, min_temperature, note_ch, note_en, horoscope) os.system("pause")
推送完消息之后,只需要在推送消息的函数中,将字典中每个元素都发送到公众号端即可:
data = { ... "note_ch": { "value": note_ch, "color": get_color() }, "horoscope1_0": { "value": horoscope['horoscope1'][0], "color": get_color() }, "horoscope1_1": { "value": horoscope['horoscope1'][1], "color": get_color() }, "horoscope1_2": { "value": horoscope['horoscope1'][2], "color": get_color() }, "horoscope1_3": { "value": horoscope['horoscope1'][3], "color": get_color() }, "horoscope1_4": { "value": horoscope['horoscope1'][4], "color": get_color() }, "horoscope1_5": { "value": horoscope['horoscope1'][5], "color": get_color() }, "horoscope2_0": { "value": horoscope['horoscope2'][0], "color": get_color() }, "horoscope2_1": { "value": horoscope['horoscope2'][1], "color": get_color() }, "horoscope2_2": { "value": horoscope['horoscope2'][2], "color": get_color() }, "horoscope2_3": { "value": horoscope['horoscope2'][3], "color": get_color() }, "horoscope2_4": { "value": horoscope['horoscope2'][4], "color": get_color() }, "horoscope2_5": { "value": horoscope['horoscope2'][5], "color": get_color() }, } } ....(代码省略) response = post(url, headers=headers, json=data).json() if response["errcode"] == 40037: print("推送消息失败,请检查模板id是否正确") elif response["errcode"] == 40036: print("推送消息失败,请检查模板id是否为空") elif response["errcode"] == 40003: print("推送消息失败,请检查微信号是否正确") elif response["errcode"] == 0: print("推送消息成功") else: print(response)
然后在公众号测试的将信息拼接起来就好了(格式和上面相同)
上述内容都是在python函数中进行了修改,可以简单看一下代码 很容易懂的,主要就是将获得的星座运势信息进行重新处理一下
from wechat-public-account-push.
Related Issues (20)
- 1 HOT 1
- 为网站生成markdown或html
- 模板消息如何配置 HOT 1
- 文档实在太乱了。。。。。。 HOT 1
- Gitee-go,在复制使用你的脚本时,依然看不到流水线任务生成 HOT 1
- 如何取消“定时执行的任务需要每隔 60 天激活一次”
- 支持青龙部署吗
- 求整理入门文档 HOT 1
- 最新版的阿里云函数怎么部署啊??
- 📌 如何修复因2023-05-04微信推送服务规范整改,导致推送服务异常? HOT 6
- JS这个怎么运行啊 HOT 1
- 调用天行热搜接口,运行报错,提示找不到城市或省份
- 天气类接口失效 HOT 1
- 您当前填写的province: 【未知】, 找不到该城市或省份,城市天气可能会因此不准确。请知悉
- 天气/城市类接口数据已失效 HOT 2
- 服务器上定时推送报错 HOT 2
- 调取节假日的接口报错 HOT 5
- 需求收集 HOT 3
- 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechat-public-account-push.