func doWapPay() []byte { cli := NewaliClient(con_privatekey,con_pubickey,"https://openapi.alipaydev.com/gateway.do") cli.FillDefaultParams() cli.PutMapSysParams(map[string]string{ "app_id": "您的app_id", "notify_url": "http://test.xxx.com/notify", }) cli.PutMapAppParams(map[string]string{ "subject": "测试", "out_trade_no": "2000100001", "seller_id": "商户号", }) cli.PutAppAnyParams("total_amount",1.00) cli.PutAppAnyParams("extend_params",map[string]string{ "sys_service_provider_id": "服务商id", }) resp,err := cli.PageExecute("alipay.trade.wap.pay") if err != nil { return []byte("") } return resp } func TestAliClient_Execute(t *testing.T) { h := httprouter.New() h.GET("/api/wap", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { body := doWapPay() w.Header().Set("Content-Type", "text/html; charset=utf-8") //WriteHeader一定放在Set后面 w.WriteHeader(http.StatusOK) w.Write(body) }) http.ListenAndServe("localhost:3000",h) }