Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
change a lots,maybe can't run
Browse files Browse the repository at this point in the history
  • Loading branch information
godcong committed Jun 6, 2018
1 parent c8e0baa commit 28354e8
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 128 deletions.
2 changes: 1 addition & 1 deletion app/mini/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newMiniProgram(config config.Config, application *core.Application) *Progra
client: core.NewClient(config),
}
mini0.token = core.NewAccessToken(config, mini0.client)
mini0.client.SetDataType(core.DATA_TYPE_JSON)
mini0.client.SetDataType(core.DataTypeJSON)
mini0.client.SetDomain(core.NewDomain("mini"))
return mini0
}
Expand Down
2 changes: 1 addition & 1 deletion app/official/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newOfficialAccount(config config.Config, application *core.Application) *Ac
}

client.SetDomain(domain)
client.SetDataType(core.DATA_TYPE_JSON)
client.SetDataType(core.DataTypeJSON)
return account
}

Expand Down
2 changes: 1 addition & 1 deletion app/official/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestBase_GetCallbackIp(t *testing.T) {
base := official.NewBase()
rlt := base.GetCallbackIp()
rlt := base.GetCallbackIP()
t.Log(rlt)
}

Expand Down
10 changes: 5 additions & 5 deletions app/official/qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type QrCodeScene struct {

/*QrCodeCard QrCodeCard*/
type QrCodeCard struct {
CardID string `json:"card_id,omitempty"` // "card_id": "pFS7Fjg8kV1IdDz01r4SQwMkuCKc",
Code string `json:"code"` // "code": "198374613512",
OpenID string `json:"openid,omitempty"` // "openid": "oFS7Fjl0WsZ9AMZqrI80nbIq8xrA",
IsUniqueCode bool `json:"openid,omitempty"` // "is_unique_code": false,
OuterStr string `json:"outer_str,omitempty"` // "outer_str":"12b"
CardID string `json:"card_id,omitempty"` // "card_id": "pFS7Fjg8kV1IdDz01r4SQwMkuCKc",
Code string `json:"code"` // "code": "198374613512",
OpenID string `json:"openid,omitempty"` // "openid": "oFS7Fjl0WsZ9AMZqrI80nbIq8xrA",
IsUniqueCode bool `json:"is_unique_code,omitempty"` // "is_unique_code": false,
OuterStr string `json:"outer_str,omitempty"` // "outer_str":"12b"
}

/*QrCodeCardList QrCodeCardList*/
Expand Down
7 changes: 2 additions & 5 deletions app/payment/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func newPayment(application *core.Application) *Payment {
}

client.SetDomain(domain)
client.SetDataType(core.DATA_TYPE_XML)
client.SetDataType(core.DataTypeXML)
return payment
}

Expand Down Expand Up @@ -151,8 +151,5 @@ func (p *Payment) preRequest(params util.Map) util.Map {
}

func (p *Payment) Link(url string) string {
if p.config.GetBool("Sandbox") {
return p.client.URL() + core.sandboxUrlSuffix + url
}
return p.client.URL() + url
return p.client.Link(url)
}
2 changes: 1 addition & 1 deletion app/payment/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewSecurity() *Security {
}

func (s *Security) GetPublicKey() *net.Response {
s.client.SetDataType(core.DATA_TYPE_XML)
s.client.SetDataType(core.DataTypeXML)
return s.client.SafeRequest(RISK_GETPUBLICKEY_URL_SUFFIX, util.Map{
net.REQUEST_TYPE_XML.String(): s.preRequest(util.Map{"sign_type": "MD5"}),
}, "post")
Expand Down
26 changes: 0 additions & 26 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"testing"

"github.com/godcong/wego/app/official"
"github.com/godcong/wego/core/menu"
)

Expand All @@ -17,28 +16,3 @@ func TestCoreButton(t *testing.T) {
v, _ := json.Marshal(b3)
log.Println(string(v))
}

func TestCoreMenu(t *testing.T) {
menus := official.NewMenu()

b1 := menu.NewClickButton("hello1", "run1")
b2 := menu.NewClickButton("hello2", "run2")
b3 := menu.NewClickButton("hello3", "run3")
b4 := menu.NewClickButton("hello4", "run4")
b5 := menu.NewClickButton("h2", "gogogo")
//m2 := menu.NewClickButton("main2", "gmmmmm")
//m3 := menu.NewClickButton("main3", "gmm33333m")
//b1.SetSub("sub", []*core.Button{b2})
b6 := menu.NewSubButton("sub1", []*menu.Button{b1, b2, b3})
b7 := menu.NewSubButton("sub2", []*menu.Button{b4, b5})
b8 := menu.NewSubButton("sub3", []*menu.Button{b1, b2, b4})
menus.AddButton(b6)
menus.AddButton(b7)
menus.AddButton(b8)
//menus.AddButton(m2)
//menus.AddButton(m3)

log.Println(menus.Create().ToString())
log.Println(menus.List().ToString())
log.Println(menus.Current().ToString())
}
2 changes: 1 addition & 1 deletion core/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (a *AccessToken) sendRequest(s string) []byte {
"secret": a.Get("secret"),
}

resp := a.client.HTTPGet(a.client.Link(cgiBinTokenUrlSuffix), m)
resp := a.client.HTTPGet(a.client.Link(tokenURLSuffix), m)
log.Debug("AccessToken|sendRequest", resp.ToString())
if resp.CheckError() != nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion core/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (a *Application) Scheme(id string) string {
m.Set("nonce_str", util.GenerateNonceStr())
m.Set("product_id", id)
m.Set("sign", GenerateSignature(m, a.Config.Get("aes_key"), MakeSignMD5))
return BIZPAYURL + m.UrlEncode()
return BizPayURL + m.UrlEncode()
}

func (a *Application) HandleNotify(typ string, f func(interface{})) {
Expand Down
62 changes: 32 additions & 30 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"github.com/godcong/wego/util"
)

/*DataType DataType */
type DataType string
type ContextKey struct{}

const (
DATA_TYPE_XML DataType = "xml"
DATA_TYPE_JSON DataType = "json"
DATA_TYPE_MULTIPART DataType = "multipart"
DataTypeXML DataType = "xml"
DataTypeJSON DataType = "json"
DataTypeMultipart DataType = "multipart"
)

type URL struct {
Expand All @@ -41,9 +42,9 @@ type Client struct {
domain *Domain
app *Application
token *AccessToken
request *net.Request
response *net.Response
client *http.Client
//request *net.Request
//response *net.Response
client *http.Client
}

var defaultCa = []byte(`
Expand Down Expand Up @@ -76,11 +77,11 @@ func (c *Client) URL() string {
return c.domain.URL()
}

func (c *Client) HttpClient() *http.Client {
func (c *Client) HTTPClient() *http.Client {
return c.client
}

func (c *Client) SetHttpClient(client *http.Client) *Client {
func (c *Client) SetHTTPClient(client *http.Client) *Client {
c.client = client
return c
}
Expand All @@ -95,7 +96,7 @@ func (c *Client) SetDataType(dataType DataType) *Client {
}

func (c *Client) HTTPPostJSON(url string, query util.Map, json interface{}) *net.Response {
c.dataType = DATA_TYPE_JSON
c.dataType = DataTypeJSON
p := util.Map{
net.REQUEST_TYPE_JSON.String(): json,
}
Expand All @@ -106,7 +107,7 @@ func (c *Client) HTTPPostJSON(url string, query util.Map, json interface{}) *net
}

func (c *Client) HTTPPostXML(url string, query util.Map, xml interface{}) *net.Response {
c.dataType = DATA_TYPE_XML
c.dataType = DataTypeXML
p := util.Map{
net.REQUEST_TYPE_XML.String(): xml,
}
Expand All @@ -117,7 +118,7 @@ func (c *Client) HTTPPostXML(url string, query util.Map, xml interface{}) *net.R
}

func (c *Client) HTTPUpload(url string, query, multi util.Map) *net.Response {
c.dataType = DATA_TYPE_MULTIPART
c.dataType = DataTypeMultipart
p := util.Map{
net.REQUEST_TYPE_MULTIPART.String(): multi,
}
Expand Down Expand Up @@ -150,8 +151,7 @@ func (c *Client) HTTPPost(url string, query util.Map, ops util.Map) *net.Respons
func (c *Client) Request(url string, ops util.Map, method string) *net.Response {
log.Debug("Request|httpClient", c.client)
c.client = buildTransport(c.Config)
c.response = request(c, url, ops, method)
return c.response
return request(c, url, ops, method)
}

func (c *Client) RequestRaw(url string, ops util.Map, method string) *net.Response {
Expand All @@ -161,8 +161,7 @@ func (c *Client) RequestRaw(url string, ops util.Map, method string) *net.Respon
func (c *Client) SafeRequest(url string, ops util.Map, method string) *net.Response {
c.client = buildSafeTransport(c.Config)
log.Debug("SafeRequest|httpClient", c.client)
c.response = request(c, url, ops, method)
return c.response
return request(c, url, ops, method)
}

func (c *Client) Link(uri string) string {
Expand All @@ -172,14 +171,17 @@ func (c *Client) Link(uri string) string {
return c.domain.Link(uri)
}

func (c *Client) GetResponse() *net.Response {
return c.response
}
/*GetRequest get net response */
//func (c *Client) GetResponse() *net.Response {
//return c.response
//}

func (c *Client) GetRequest() *net.Request {
return c.request
}
/*GetRequest get net request */
//func (c *Client) GetRequest() *net.Request {
// return c.request
//}

/*DefaultClient DefaultClient */
func DefaultClient() *Client {
return nil
}
Expand All @@ -192,9 +194,9 @@ func NewClient(config config.Config) *Client {
config = defaultConfig
}
return &Client{
request: net.DefaultRequest,
//request: net.DefaultRequest,
Config: config,
dataType: DATA_TYPE_XML,
dataType: DataTypeXML,
domain: domain,
}
}
Expand Down Expand Up @@ -258,7 +260,7 @@ func buildSafeTransport(config config.Config) *http.Client {
func request(c *Client, url string, ops util.Map, method string) *net.Response {
log.Debug("client|request", c, url, ops, method)
data := toRequestData(c, ops)
r := c.request.PerformRequest(url, method, data)
r := net.PerformRequest(url, method, data)
if r.Error() == nil {
return Do(context.Background(), c, r)
}
Expand Down Expand Up @@ -286,25 +288,25 @@ func Do(ctx context.Context, client *Client, request *net.Request) *net.Response
if r.StatusCode != http.StatusOK {
log.Debug("Do|StatusCode", r.StatusCode)
}
response = net.ParseResponse(client.request.GetRequestType(), r)
response = net.ParseResponse(request.GetRequestType(), r)

return response
}

func toRequestData(client *Client, ops util.Map) *net.RequestData {
data := client.request.RequestDataCopy()
data := net.NewRequestData()
data.Query = processQuery(ops.Get(net.REQUEST_TYPE_QUERY.String()))
data.Body = nil
if client.DataType() == DATA_TYPE_JSON {
if client.DataType() == DataTypeJSON {
data.SetHeaderJson()
data.Body = processJSON(ops.Get(net.REQUEST_TYPE_JSON.String()))
}
if client.DataType() == DATA_TYPE_XML {
if client.DataType() == DataTypeXML {
data.SetHeaderXml()
data.Body = processXML(ops.Get(net.REQUEST_TYPE_XML.String()))
}

if client.DataType() == DATA_TYPE_MULTIPART {
if client.DataType() == DataTypeMultipart {
buf := bytes.Buffer{}
writer := multipart.NewWriter(&buf)
writer = processMultipart(writer, ops.Get(net.REQUEST_TYPE_MULTIPART.String()))
Expand Down Expand Up @@ -464,7 +466,7 @@ func (u *URL) ShortURL(url string) util.Map {
ops := util.Map{
net.REQUEST_TYPE_QUERY.String(): token.KeyMap(),
}
resp := u.client.HTTPPostJSON(u.client.Link(shorturlUrlSuffix), m, ops)
resp := u.client.HTTPPostJSON(u.client.domain.Link(shortURLSuffix), m, ops)
log.Debug("URL|ShortURL", *resp)
return resp.ToMap()
}
Expand Down
12 changes: 6 additions & 6 deletions core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ const USERPAYING = "USERPAYING"
//const SSLCERT_PATH = "./cert/apiclient_cert.pem"
//const SSLKEY_PATH = "./cert/apiclient_key.pem"

const reportUrlSuffix = "/payitil/report"
const shorturlUrlSuffix = "/tool/shorturl"
const reportURLSuffix = "/payitil/report"
const shortURLSuffix = "/tool/shorturl"

const sandboxUrlSuffix = "/sandboxnew"
const sandboxSignkeyUrlSuffix = sandboxUrlSuffix + "/pay/getsignkey"

const cgiBinTokenUrlSuffix = "/cgi-bin/token"
const tokenURLSuffix = "/cgi-bin/token"

//const CUSTOM_SEND_URL_SUFFIX = "/cgi-bin/message/custom/send"

Expand All @@ -44,3 +41,6 @@ const msgrecordGetmsglistURLSuffix = "/customservice/msgrecord/getmsglist"

const clearQuotaURLSuffix = "/cgi-bin/clear_quota"
const getcallbackipURLSuffix = "/cgi-bin/getcallbackip"

const sandboxUrlSuffix = "/sandboxnew"
const sandboxSignkeyUrlSuffix = sandboxUrlSuffix + "/pay/getsignkey"
2 changes: 1 addition & 1 deletion core/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *Sandbox) SandboxSignKey() []byte {
m.Set("nonce_str", util.GenerateNonceStr())
sign := GenerateSignature(m, s.Get("aes_key"), MakeSignMD5)
m.Set("sign", sign)
resp := s.client.Request(s.client.Link(sandboxSignkeyUrlSuffix), m, "post")
resp := s.client.Request(s.client.domain.Link(sandboxSignkeyUrlSuffix), m, "post")

return resp.ToBytes()

Expand Down
4 changes: 0 additions & 4 deletions mini_program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ func TestGetAuth(t *testing.T) {
log.Println(wego.GetMiniProgram().Auth().Session("1234"))
}

func TestGetAppCode(t *testing.T) {
log.Println(wego.GetAppCode().Get("path", nil))
}

func TestNewAppCode(t *testing.T) {
var v []string
log.Println(v == nil)
Expand Down
20 changes: 10 additions & 10 deletions net/header.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net

const (
CONTENT_TYPE_JSON = "application/json"
CONTENT_TYPE_HTML = "text/html"
CONTENT_TYPE_XML = "application/xml"
CONTENT_TYPE_XML2 = "text/xml"
CONTENT_TYPE_Plain = "text/plain"
CONTENT_TYPE_POSTForm = "application/x-www-form-urlencoded"
CONTENT_TYPE_MultipartPOSTForm = "multipart/form-data"
CONTENT_TYPE_PROTOBUF = "application/x-protobuf"
CONTENT_TYPE_MSGPACK = "application/x-msgpack"
CONTENT_TYPE_MSGPACK2 = "application/msgpack"
ContentTypeJson = "application/json"
ContentTypeHtml = "text/html"
ContentTypeXml = "application/xml"
ContentTypeXml2 = "text/xml"
ContentTypePlain = "text/plain"
ContentTypePostForm = "application/x-www-form-urlencoded"
ContentTypeMultipartPostForm = "multipart/form-data"
ContentTypeProtoBuf = "application/x-protobuf"
ContentTypeMsgPack = "application/x-msgpack"
ContentTypeMsgPack2 = "application/msgpack"
)
Loading

0 comments on commit 28354e8

Please sign in to comment.