Exemplo n.º 1
0
func TestGetMobileGis(t *testing.T) {
	r := &request.AlipayMobilePublicGisGetRequest{
		BizContent: "{'userId':'" + userId + "'}",
	}
	resp, err := alipayClient.Execute(r)

	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	log.Debugf("%+v", resp)
}
Exemplo n.º 2
0
func TestGetOpenId(t *testing.T) {
	r := &request.AlipaySystemOauthTokenRequest{
		GrantType: "authorization_code",
		Code:      "6d46274d082f4f96807ca49e3e30cX92",
	}
	resp, err := alipayClient.Execute(r)

	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	log.Debugf("%+v", resp)

}
Exemplo n.º 3
0
func TestDefaultClientWork(t *testing.T) {

	ImgText := "{'articles':[{'actionName':'立即查看','desc':'这是图文内容','imageUrl':'http://pic.alipayobjects.com/e/201311/1PaQ27Go6H_src.jpg','title':'这是标题','url':'https://www.alipay.com/'}],'msgType':'image-text','toUserId':'kquy1L6pBsGPHDYCYeBhLJqKo7ILToCxhO4skMe5bRK-S4-HyunMvYTqiRYEUD+U01'}"
	r := &request.AlipayMobilePublicMessageCustomSendRequest{
		BizContent: ImgText,
	}

	resp, err := alipayClient.Execute(r)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	log.Debugf("%+v", resp)

}
Exemplo n.º 4
0
// 实现接口
func (d *DefaultAlipayClient) ExecuteWithToken(r request.AlipayRequest, token string) (response.AlipayResponse, error) {

	// 请求
	msg, rp, err := d.post(r, token)
	if err != nil {
		return nil, err
	}

	log.Debugf("alipay return : %s", msg)

	// body
	resp := r.GetResponse()
	resp.SetBody(msg)

	// replace
	k := xstrings.ToSnakeCase(resp.ToStr())
	if strings.Contains(msg, k) {
		msg = strings.Replace(msg, k, "response", 1)
	} else {
		msg = strings.Replace(msg, "error_response", "response", 1)
	}

	// convert
	var t = &struct {
		Response response.AlipayResponse `json:"response"`
		Sign     string                  `json:"sign"`
	}{
		resp, "",
	}
	err = json.Unmarshal([]byte(msg), t)
	if err != nil {
		log.Error(err)
	}

	// 当发生安全机制接入错误时
	// 详细见https://fuwu.alipay.com/platform/doc.htm#c09
	if !resp.IsSuccess() {
		logger.SecureError(rp, resp)
	}
	return resp, nil
}