- LimitMixedStringLen

This commit is contained in:
gazebo
2019-04-11 14:08:41 +08:00
parent ff99b78137
commit ab458274c9
4 changed files with 80 additions and 11 deletions

View File

@@ -2,6 +2,10 @@ package weixinapi
import "git.rosy.net.cn/baseapi/utils"
const (
MaxRemarkByteCount = 30
)
func (a *API) CBSetToken(newToken string) bool {
curToken := a.CBGetToken()
if curToken != newToken {
@@ -49,10 +53,11 @@ func (a *API) CBMessageTemplateSend(userOpenID, templateID, downloadURL string,
return err
}
// remark的字节数不超过30个字节
func (a *API) CBUpdateRemark(userOpenID, remark string) (err error) {
bodyJson := map[string]interface{}{
"openid": userOpenID,
"remark": remark,
"remark": utils.LimitMixedStringLen(remark, MaxRemarkByteCount),
}
_, err = a.AccessAPI("cgi-bin/user/info/updateremark", nil, string(utils.MustMarshal(bodyJson)))
return err

View File

@@ -31,7 +31,9 @@ func TestCBMessageTemplateSend(t *testing.T) {
}
func TestCBUpdateRemark(t *testing.T) {
err := api.CBUpdateRemark("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", "徐大仙")
remark := "一二三四五六七八九十"
t.Log(len(remark))
err := api.CBUpdateRemark("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", remark)
if err != nil {
t.Log(err)
}