首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Textlocal发送模板消息

通过Textlocal发送模板消息
EN

Stack Overflow用户
提问于 2017-02-04 04:55:14
回答 2查看 7.5K关注 0票数 1

我得到的答复是:

{“错误”:{“代码”:204,“消息”:“无效消息内容”},“状态”:“失败”}

当我尝试使用此模板提交消息时,我已向Textlocal注册:

谢谢你在*登记。请输入验证代码%%\OTP^{“inputtype”:"text“、"maxlength”:“6”}%以完成注册。

如何使用此模板发送消息?我目前的代码是:

代码语言:javascript
复制
def sending_sms(number,otp):
    url = 'http://api.textlocal.in/send/'
    msg = 'Thank you for registering with RTM. Please enter the verification code %%|OTP^{"inputtype" : "text", "maxlength" : "6"}%% to complete the registration.'
    post_fields = ({"username":"admin@example.in","password":"P@ssword","numbers":number,"message":msg})

    request = Request(url, urlencode(post_fields).encode())
    print request
    json = urlopen(request).read().decode()
    print json
    return json
EN

回答 2

Stack Overflow用户

发布于 2017-02-04 07:20:30

您正在将模板作为您的消息发送。您需要发送一个填充模板(即替换实际的OTP代码,而不是%%|OTP... )。

从医生那里:

如何通过API?发送模板 Textlocal根据所有已批准的模板检查您的邮件,只有当消息与您帐户中的任何已批准模板完全匹配时,才会传递该消息。

  1. 从数据库/应用程序中获取动态参数,并在API中传递最终消息内容-例如:如果您批准的模板是:Thank you for registering with Textlocal. Your verification code is XXXX 需要传递的消息内容是:Thank you for registering with Textlocal. Your verification code is 1123 (其中代码由应用程序生成)

  1. 在您的代码中,动态参数必须分配一个变量(理想情况下是长字符串或数组),该变量根据移动号码从数据库/应用程序中分配一个特定值。-例如:在PHP中,$message = rawurlencode('Thank you for registering with Textlocal. Your verification code is $otp') 其中$otp是动态参数代码中的标识符。

值得注意的一点:

  1. 模板名称、占位符文本都供您参考。它们不应该添加到API中。
  2. Textlocal中的“message”参数应该只有完整的消息内容和替换的动态参数。(有关参数详细信息,请参阅:http://api.textlocal.in/docs/ )
  3. 所有特殊字符都需要进行URL编码(编码值请参阅:http://meyerweb.com/eric/tools/dencoder/ )
  4. 如果模板有换行符-在API中用%n替换换行符。
票数 2
EN

Stack Overflow用户

发布于 2020-12-15 08:45:01

是的,根据@Grisha Levit的答案。您只需在消息变量本身中发送OTP,而不是%%扣分OTP^{“inputtype”:"text","maxlength“:”6“}%。

解决这个问题

改变这个

代码语言:javascript
复制
msg = 'Thank you for registering with RTM. Please enter the verification code %%|OTP^{"inputtype" : "text", "maxlength" : "6"}%% to complete the registration.'

对此

代码语言:javascript
复制
otp = 123456
msg = 'Thank you for registering with RTM. Please enter the verification code {otp} to complete the registration.'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42036628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档