Пример #1
0
func (d *DefaultAlipayClient) post(r request.AlipayRequest, token string) (string, map[string]string, error) {
	// 获取必须参数
	rp := make(map[string]string)
	rp[constants.AppId] = d.AppId
	rp[constants.Method] = r.GetApiMethod()
	rp[constants.SignType] = signType // TODO
	rp[constants.Timestamp] = time.Now().Format("2006-01-02 15:03:04")
	rp[constants.Version] = r.GetApiVersion()
	rp[constants.Charset] = d.Charset
	utils.PutAll(rp, r.GetTextParams())
	// 可选参数
	// rp[constants.Format] = d.Format

	// 请求报文
	content := utils.PrepareContent(rp)
	// 签名
	signed, err := sign.RsaSign(content, d.PrivKey)
	rp[constants.Sign] = signed

	// 编码查询参数
	values := utils.BuildQuery(rp)
	// 请求
	result, err := http.Post(d.ServerURL, "application/x-www-form-urlencoded;charset=utf-8", strings.NewReader(values.Encode()))
	if err != nil {
		log.Error(err)
	}
	msg, err := ioutil.ReadAll(result.Body)
	if err != nil {
		log.Error(err)
	}
	return string(msg), rp, err
}
func (r *AlipayPassSyncUpdateRequest) GetTextParams() map[string]string {
	params := make(map[string]string)
	params["channel_id"] = r.ChannelId
	params["ext_info"] = r.ExtInfo
	params["pass"] = r.Pass
	params["serial_number"] = r.SerialNumber
	params["status"] = r.Status
	params["verify_code"] = r.VerifyCode
	params["verify_type"] = r.VerifyType
	//utils.putAll(params,userParams)
	if len(r.UdfParams) > 0 {
		utils.PutAll(params, r.UdfParams)
	}
	return params
}