调试通过webservice
diff --git a/webservice.go b/webservice.go
index d11fc1e..732f8be 100644
--- a/webservice.go
+++ b/webservice.go
@@ -1,11 +1,10 @@
-package main
-
-//swwebservice
+package swservice
 
 import (
 	"bytes"
 	"crypto/hmac"
 	"crypto/sha1"
+	"encoding/hex"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -32,39 +31,6 @@
 	session_key    string
 }
 
-type MessageReader struct {
-	FuncNo      int
-	ColumnNames []string
-	ColumnDescs []string
-	RowData     [][]interface{}
-}
-
-type MessageWriter struct {
-	FuncNo      int
-	Attributes  map[string]string
-	ColumnNames []string
-	ColumnDescs []string
-	RowData     [][]interface{}
-}
-
-func NewMessageWriter(funcno int) *MessageWriter {
-	return &MessageWriter{
-		FuncNo:      funcno,
-		Attributes:  make(map[string]string),
-		ColumnNames: make([]string, 0),
-		ColumnDescs: make([]string, 0)}
-}
-func (m *MessageWriter) SetAttr(name, value string) {
-	m.Attributes[name] = value
-}
-func (m *MessageWriter) AddCol(name, desc string) {
-	m.ColumnNames = append(m.ColumnNames, name)
-	m.ColumnDescs = append(m.ColumnDescs, desc)
-}
-func (m *MessageWriter) AddRow(data []string) {
-	//	m.RowData[] = append(m.RowData)
-}
-
 func (w *WebSession) DoGet(uri string, params map[string]string) (*http.Response, error) {
 	transport := http.Transport{Dial: dailTimeout}
 
@@ -73,18 +39,13 @@
 	full_url := w.BaseUrl + uri
 
 	vl := url.Values{}
-	//	vl.Add("app_id", w.AppId)
-	//	ts := w.GetTimestamp()
-	//	vl.Add("timestamp", ts)
 
 	if params != nil {
 		for k, v := range params {
 			vl.Add(k, v)
 		}
 	}
-	//	vl.Add("sign", w.Sign(ts, vl.Encode()))
 	full_url = full_url + "?" + vl.Encode()
-	fmt.Printf("url: %v\n", full_url)
 	return client.Get(full_url)
 }
 
@@ -95,34 +56,31 @@
 }
 
 func (w *WebSession) Sign(message string) string {
-	//	pridata := accesstoken + timestamp
-	mac := hmac.New(sha1.New, []byte(w.session_key))
+	mac := hmac.New(sha1.New, []byte(w.Appsecret))
 	mac.Write([]byte(message))
 	res := mac.Sum(nil)
-	//	res := sha1.Sum([]byte(pridata))
-	return string(res[0:])
+	return hex.EncodeToString(res)
 }
 
-func (w *WebSession) DoPost(uri string, param map[string]string, json_data []byte) (*http.Response, error) {
+func (w *WebSession) DoPost(uri string, param map[string]string) (*http.Response, error) {
 	transport := http.Transport{Dial: dailTimeout}
 	client := &http.Client{Transport: &transport}
-	vl := url.Values{}
-	vl.Add("app_id", w.AppId)
+	param["app_id"] = w.AppId
+	param["term_id"] = w.TermId
+	param["sign_method"] = "HMAC"
+	param["session_key"] = w.session_key
 	ts := w.GetTimestamp()
-	vl.Add("timestamp", ts)
-	vl.Add("sign", w.Sign(ts+vl.Encode()))
-	if param != nil {
-		for k, v := range param {
-			vl.Add(k, v)
-		}
-	}
-	if json_data != nil {
-		vl.Add("request_data", string(json_data))
-	}
+	param["timestamp"] = ts
+	param["sign"] = w.Sign(w.AppId + w.TermId + w.session_key + ts)
 
 	full_url := w.BaseUrl + uri
 	log.Debugf("Url=%v", full_url)
-	r, err := client.Post(full_url, "application/x-www-form-urlencoded", bytes.NewReader([]byte(vl.Encode())))
+	data, err := json.Marshal(param)
+	if err != nil {
+		return nil, err
+	}
+	var r *http.Response
+	r, err = client.Post(full_url, "application/json", bytes.NewReader(data))
 	if err != nil || r.StatusCode != 200 {
 		log.Errorf("Status=%v, err=%v", r, err)
 	}
@@ -158,7 +116,7 @@
 		AccessToken string `json:"access_token"`
 	}
 
-	uri := fmt.Sprintf("/yktapi/services/authservice/getauth/%v/getaccesstoken", w.AppId)
+	uri := fmt.Sprintf("/authservice/getauth/%v/getaccesstoken", w.AppId)
 
 	params := make(map[string]string)
 	params["term_id"] = w.TermId
@@ -189,7 +147,7 @@
 		CardKey    string `json:"card_key"`
 	}
 
-	uri := fmt.Sprintf("/yktapi/services/authservice/getauth/%v", w.AppId)
+	uri := fmt.Sprintf("/authservice/getauth/%v", w.AppId)
 
 	params := make(map[string]string)
 	params["term_id"] = w.TermId
@@ -207,60 +165,28 @@
 
 	body, err := ioutil.ReadAll(r.Body)
 	r.Body.Close()
-	//	contents := make([]byte, r.ContentLength)
-	//	r.Body.Read(contents)
 
 	s := &FormJson{}
 	err = json.Unmarshal(body, &s)
-	fmt.Printf("[%v]\n", string(body))
 	if err != nil {
 		log.Errorf("json unmarshal err %v", err)
 	}
 	w.session_key = s.SessionKey
 	return nil
 }
-func (w *WebSession) PushTransdtl(msg MessageWriter) {
-	type FormJson struct {
+
+func (w *WebSession) CallYKTApi(request *MessageWriter) (*MessageReader, error) {
+	call_data := request.Serialize()
+	params := make(map[string]string)
+	params["funcdata"] = call_data
+	r, err := w.DoPost("/ecardservice/ecardapi", params)
+
+	if err != nil || r.StatusCode != 200 {
+		log.Errorf(" err = %v\n", err)
+		return nil, err
 	}
-	//	uri := fmt.Sprintf("/yktapi/services/ecardservice")
 
-	//	params := make(map[string]string)
-	//	params["term_id"] = w.TermId
-	//	params["access_token"] = w.AccessToken
-	//	params["timestamp"] = w.GetTimestamp()
-	//	signMsg := w.AppId + w.TermId + w.session_key + params["timestamp"]
-	//	params["sign"] = w.Sign(signMsg)
-	//	params["sign_method"] = "HMAC-SHA1"
-	//	temp := json.Marshal(msg)
-	//	params["funcdata"] = string(temp[0:])
-
-	//	r, err := w.DoPost(uri, params, nil)
-	//	if err != nil || r.StatusCode != 200 {
-	//		log.Errorf("Status = %v, err = %v\n", r.StatusCode, err)
-	//		return
-	//	}
-	//	if r.ContentLength == -1 {
-	//		log.Error("no response")
-	//		return
-	//	}
-	//	contents := make([]byte, r.ContentLength)
-	//	r.Body.Read(contents)
-
-	//	var s FormJson
-	//	err = json.Unmarshal(contents, &s)
-	//	if err != nil {
-	//		log.Errorf("json unmarshal err %v", err)
-	//		return
-	//	}
-	//		temp = s.
-}
-
-func main() {
-	websession := NewSession("10001", "", "100", "http://172.28.200.122:8080", 3)
-	fmt.Println(websession.AppId)
-	if err := websession.Auth(); err != nil {
-		fmt.Printf("Error : %v\n", err)
-	}
-	//	websession.GetAppAccessKey()
-
+	body, err := ioutil.ReadAll(r.Body)
+	r.Body.Close()
+	return NewMessageReader(body), nil
 }