Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求参数类型转换错误 #3

Open
hsg4ok opened this issue Jul 13, 2018 · 1 comment
Open

请求参数类型转换错误 #3

hsg4ok opened this issue Jul 13, 2018 · 1 comment

Comments

@hsg4ok
Copy link

hsg4ok commented Jul 13, 2018

测试环境:
macOS 10.13.6
golang 1.10

自己在做测试的时候发现如果请求参数中有int类型参数的话,钉钉接口就会报错。原因是受到参数类型转换方式的影响。

SDK中将interface{}转换为string类型的方式为:fmt.Sprintf("%s", v),这种方式将int类型的参数转换为string类型,然后再组合到请求参数时,会带附加字符。钉钉服务器参数值验证不通过。具体位置为:
request.go 146行和181行。

使用自己的类型转换方法之后,测试通过。

具体参数类型转换方法:

`func String(args ...interface{}) string {
value := args[0]
var precision int = 12

switch value.(type) {
case string:
	v, _ := value.(string)
	return v
case int:
	v, _ := value.(int)
	return strconv.Itoa(v)
case int32:
	v, _ := value.(int32)
	return strconv.FormatInt(int64(v), 10)
case int64:
	v, _ := value.(int64)
	return strconv.FormatInt(v, 10)
case float32:
	v, _ := value.(float32)
	if len(args) >= 2 {
		precision = args[1].(int)
	}
	return strconv.FormatFloat(float64(v), 'f', precision, 64)
case float64:
	v, _ := value.(float64)
	if len(args) >= 2 {
		precision = args[1].(int)
	}
	return strconv.FormatFloat(v, 'f', precision, 64)
case template.HTML:
	return string(value.(template.HTML))
default:
	return ""
}

}`

@icepy
Copy link
Collaborator

icepy commented Jul 23, 2018

可以发个PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants