Esempio n. 1
0
// FetchAccessToken could be used to fetch access token for wechat qy dev.
func FetchAccessToken(corpID, corpSecret string) (string, float64, error) {
	requestLine := strings.Join([]string{accessTokenFetchURL,
		"?corpid=",
		corpID,
		"&corpsecret=",
		corpSecret}, "")

	return pb.FetchAccessToken(requestLine)
}
Esempio n. 2
0
// FetchAccessToken could be used to fetch access token for wechat qy dev.
func FetchAccessToken(appID, appSecret string) (string, float64, error) {
	requestLine := strings.Join([]string{accessTokenFetchURL,
		"?grant_type=client_credential&appid=",
		appID,
		"&secret=",
		appSecret}, "")

	return pb.FetchAccessToken(requestLine)
}
Esempio n. 3
0
func TestSecretInvalid(t *testing.T) {
	myCorpID := "wxfd4448417439fd3x"
	mySecret := "p_VQovLdSPNXP0caBalViFvAG_mIpR4bECn-fD1F9JRBut471AcJYXK14SOG1Zle"
	myURL := accessTokenFetchURL + "?corpid=" + myCorpID + "&corpsecret=" + mySecret

	_, _, err := pb.FetchAccessToken(myURL)
	errStr := fmt.Sprintf("%s", err)
	if errStr != "invalid corpSecret" {
		t.Errorf("Errmsg: want[%s], but actually[%s]", "invalid corpSecret", errStr)
	}
}
Esempio n. 4
0
func TestFetchAccessTokenOk(t *testing.T) {
	myCorpID := "wxfd4448417439fd3x"
	mySecret := "p_VQovLdSPNXP0caBalViFvAG_mIpR4bECn-fD1F9JRBut471AcJYXK14SOG1Zld"
	myURL := accessTokenFetchURL + "?corpid=" + myCorpID + "&corpsecret=" + mySecret

	token, expiresIn, err := pb.FetchAccessToken(myURL)
	if err != nil {
		t.Fatal("Fetch accesstoken error:", err)
	}

	if token != accessToken {
		t.Errorf("Token: want[%s], but actually[%s]", accessToken, token)
	}

	if expiresIn != float64(7200) {
		t.Errorf("ExpiresIn: want[%s], but actually[%s]", accessToken, token)
	}
}