Giter Site home page Giter Site logo

Comments (2)

shangzeng avatar shangzeng commented on August 17, 2024

大佬能更详细一些么。。

from wechat-public-account-push.

StriveZs avatar StriveZs commented on August 17, 2024

大佬能更详细一些么。。

现在的问题是存在可显示字符的数量限制,一次可能只能显示大概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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.