Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
代码直观
  • Loading branch information
aimuz committed Jul 18, 2018
1 parent aa29c99 commit afd3452
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
7 changes: 7 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ const (
//https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
// AccessTokenURL code获取access_token
AccessTokenURL = "https://api.weixin.qq.com/sns/oauth2/access_token"

// RefreshTokenURL 重新获取access_token
RefreshTokenURL = "https://api.weixin.qq.com/sns/oauth2/refresh_token"

// UserInfoURL 通过access_token获取userInfo
UserInfoURL = "https://api.weixin.qq.com/sns/userinfo"

// CheckAccessTokenURL 检验授权凭证(access_token)是否有效
CheckAccessTokenURL = "https://api.weixin.qq.com/sns/auth"

// JsCode2SessionURL 临时登录凭证校验接口
JsCode2SessionURL = "https://api.weixin.qq.com/sns/jscode2session"

// SendRedPackURL 发送现金红包
SendRedPackURL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"
)
5 changes: 0 additions & 5 deletions login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (m *WxConfig) GetWxAccessToken(code string) (accessToken *WxAccessToken, er
if err != nil {
return accessToken, err
}

if accessToken.ErrMsg != "" {
return accessToken, errors.New(accessToken.ErrMsg)
}
Expand Down Expand Up @@ -168,7 +167,6 @@ func (m *WxAccessToken) GetUserInfo() (wxUserInfo *WxUserInfo, err error) {
if err != nil {
return nil, err
}

if wxUserInfo.OpenID == "" {
return wxUserInfo, errors.New(wxUserInfo.ErrMsg)
}
Expand Down Expand Up @@ -200,7 +198,6 @@ func (m *WxAccessToken) GetRefreshToken(appid string) error {
if err != nil {
return err
}

err = json.Unmarshal(body, &m)
if err != nil {
return err
Expand Down Expand Up @@ -236,7 +233,6 @@ func (m *WxAccessToken) CheckAccessToken() (ok bool, err error) {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
}{}

err = json.Unmarshal(body, &result)
if err != nil {
return ok, err
Expand Down Expand Up @@ -269,7 +265,6 @@ func (m *WxConfig) GetJsCode2Session(code string) (wXBizDataCrypt *WXBizDataCryp
for k, v := range t {
params.Set(k, v)
}

body, err := utils.NewRequest("GET", common.JsCode2SessionURL, []byte(params.Encode()))
if err != nil {
return wXBizDataCrypt, err
Expand Down
2 changes: 0 additions & 2 deletions pay/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ type (
func NewUnifiedOrder(unifiedOrder interface{}) (unifiedOrderResp UnifiedOrderResp, err error) {

data, err := xml.Marshal(unifiedOrder)

if err != nil {
return unifiedOrderResp, err
}

body, err := utils.NewRequest("POST", common.UnifiedOrderURL, data)

if err != nil {
return unifiedOrderResp, err
}
Expand Down
8 changes: 0 additions & 8 deletions pay/pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type (
func (m *WePay) AppPay(totalFee int) (results *AppPayRet, outTradeNo string, err error) {

outTradeNo = utils.GetTradeNO(m.MchID)

appUnifiedOrder := &AppUnifiedOrder{
UnifiedOrder: UnifiedOrder{
AppID: m.AppID,
Expand All @@ -71,9 +70,7 @@ func (m *WePay) AppPay(totalFee int) (results *AppPayRet, outTradeNo string, err
NonceStr: utils.RandomNumString(16, 32),
},
}

t, err := utils.Struct2Map(appUnifiedOrder)

if err != nil {
return results, outTradeNo, err
}
Expand All @@ -86,7 +83,6 @@ func (m *WePay) AppPay(totalFee int) (results *AppPayRet, outTradeNo string, err
appUnifiedOrder.Sign = strings.ToUpper(sign)

unifiedOrderResp, err := NewUnifiedOrder(appUnifiedOrder)

if err != nil {
return results, outTradeNo, err
}
Expand Down Expand Up @@ -120,7 +116,6 @@ func (m *WePay) AppPay(totalFee int) (results *AppPayRet, outTradeNo string, err
func (m *WePay) WaxPay(totalFee int, openID string) (results *WaxPayRet, outTradeNo string, err error) {

outTradeNo = utils.GetTradeNO(m.MchID)

wxaUnifiedOrder := &WxaUnifiedOrder{
UnifiedOrder: UnifiedOrder{
AppID: m.AppID,
Expand All @@ -135,9 +130,7 @@ func (m *WePay) WaxPay(totalFee int, openID string) (results *WaxPayRet, outTrad
},
OpenID: openID,
}

t, err := utils.Struct2Map(wxaUnifiedOrder)

if err != nil {
return results, outTradeNo, err
}
Expand Down Expand Up @@ -165,7 +158,6 @@ func (m *WePay) WaxPay(totalFee int, openID string) (results *WaxPayRet, outTrad
}

r, err := utils.Struct2Map(results)

if err != nil {
return results, outTradeNo, err
}
Expand Down
9 changes: 9 additions & 0 deletions pay/redpack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pay

/*
redpack 红包
*/

func (WePay) SendPack() {

}
3 changes: 3 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func NewRequest(method, url string, data []byte) (body []byte, err error) {
}

resp, err := client.Do(req)
if err != nil {
return nil, err
}

body, err = ioutil.ReadAll(resp.Body)
if err != nil {
Expand Down

0 comments on commit afd3452

Please sign in to comment.