Browse Source

mini h5

master
黄梓健 5 years ago
parent
commit
1bb7bc5dc5
  1. 4
      controllers/client/login.go
  2. 1
      go.mod
  3. 4
      go.sum
  4. 1
      libs/wechat/wx.go
  5. 135
      libs/wx/order.go

4
controllers/client/login.go

@ -1,6 +1,8 @@
package client
import (
mpoauth2 "github.com/chanxuehong/wechat/mp/oauth2"
"github.com/chanxuehong/wechat/oauth2"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/jwt"
"hudongzhuanjia/libs/wx"
@ -57,9 +59,11 @@ func (t *UserCtl) EntryLogin() {
})
}
// snsapi_userinfo
func (t *UserCtl) WxLogin() {
activityId := t.MustGetInt64("activity_id")
wxcode := t.MustGet("code")
//kind, _ := t.Get("type") // mini 小程序登陆 base 静默授权 userinfo 或者为空 非静默授权
activity, exist, err := activity_service.GetActivityById(activityId)
t.CheckErr(err)

1
go.mod

@ -6,6 +6,7 @@ require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.1
github.com/agrison/go-tablib v0.0.0-20160310143025-4930582c22ee
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/chanxuehong/wechat v0.0.0-20190521093015-fafb751f9916 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect

4
go.sum

@ -41,6 +41,10 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c=
github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/chanxuehong/rand v0.0.0-20180830053958-4b3aff17f488/go.mod h1:h13adSJmQ5tsaV9bR72eTp7ePXJ2WIWyK6heLeietxA=
github.com/chanxuehong/util v0.0.0-20181116100727-caf892acd09c/go.mod h1:oCc2u0egGweOE68RdURGznc2LgbCrdGAAkXOQw2CuNM=
github.com/chanxuehong/wechat v0.0.0-20190521093015-fafb751f9916 h1:uD+wIaoJkd0RznEoYFhjA4dHS30iP5D+TLTeYb+5Z4U=
github.com/chanxuehong/wechat v0.0.0-20190521093015-fafb751f9916/go.mod h1:BO4IXwEfyapf9pSD8vEInR6JjnmQBxBw7VJKB3NZuiI=
github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=

1
libs/wechat/wx.go

@ -0,0 +1 @@
package wechat

135
libs/wx/order.go

@ -1,135 +0,0 @@
package wx
// import (
// "bytes"
// "crypto/tls"
// "crypto/x509"
// "encoding/xml"
// "io/ioutil"
// "net/http"
// "net/url"
// "strconv"
// "github.com/ouxuanserver/osmanthuswine/src/helper"
// )
// const KEY = "wechat_key"
// var transfers = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
// type Order struct {
// XMLName xml.Name `xml:"xml"`
// MchAppid string `xml:"mch_appid"`
// Mchid string `xml:"mchid"`
// DeviceInfo string `xml:"device_info"`
// NonceStr string `xml:"nonce_str"`
// Sign string `xml:"sign"`
// PartnerTradeNo string `xml:"partner_trade_no"`
// Openid string `xml:"openid"`
// CheckName string `xml:"check_name"`
// ReUserName string `xml:"re_user_name"`
// Amount int `xml:"amount"`
// Desc string `xml:"desc"`
// SpbillCreateIp string `xml:"spbill_create_ip"`
// }
// type OrderResult struct {
// ReturnCode string `xml:"return_code"`
// ReturnMsg string `xml:"return_msg"`
// ResultCode string `xml:"result_code"`
// ErrCode string `xml:"err_code"`
// ErrCodeDes string `xml:"err_code_des"`
// MchAppid string `xml:"mch_appid"`
// Mchid string `json:"mchid"`
// DeviceInfo string `json:"device_info"`
// NonceStr string `json:"nonce_str"`
// PartnerTradeNo string `xml:"partner_trade_no"`
// PaymentNo string `xml:"payment_no"`
// PaymentTime string `xml:"payment_time"`
// }
// //付款,成功返回自定义订单号,微信订单号,true,失败返回错误信息,false
// func Withdraw(appid, mchid, openid, amount, partnerTradeNo, desc, clientIp string) (*OrderResult, error) {
// order := Order{}
// order.MchAppid = appid
// order.Mchid = mchid
// order.Openid = openid
// order.Amount, _ = strconv.Atoi(amount)
// order.Desc = desc
// order.PartnerTradeNo = partnerTradeNo
// order.DeviceInfo = "WEB"
// order.CheckName = "NO_CHECK" //NO_CHECK:不校验真实姓名 FORCE_CHECK:强校验真实姓名
// order.SpbillCreateIp = clientIp
// order.NonceStr = helper.CreateUUID()
// order.Sign = md5WithdrawOrder(order)
// xmlBody, _ := xml.MarshalIndent(order, " ", " ")
// resp, err := SecurePost(transfers, xmlBody)
// if err != nil {
// return nil, err
// }
// defer resp.Body.Close()
// bodyByte, _ := ioutil.ReadAll(resp.Body)
// res := new(OrderResult)
// err = xml.Unmarshal(bodyByte, res)
// return res, err
// }
// func md5WithdrawOrder(order Order) string {
// o := url.Values{}
// o.Add("mch_appid", order.MchAppid)
// o.Add("mchid", order.Mchid)
// o.Add("device_info", order.DeviceInfo)
// o.Add("partner_trade_no", order.PartnerTradeNo)
// o.Add("check_name", order.CheckName)
// o.Add("amount", strconv.Itoa(order.Amount))
// o.Add("spbill_create_ip", order.SpbillCreateIp)
// o.Add("desc", order.Desc)
// o.Add("nonce_str", order.NonceStr)
// o.Add("openid", order.Openid)
// r, _ := url.QueryUnescape(o.Encode())
// return helper.Md5(r + "&key=" + KEY)
// }
// var (
// wechatCertPath = `./cert/cert.pem`
// wechatKeyPath = `./cert/key.pem`
// wechatCAPath = `./cert/rootca.pem`
// )
//采用单例模式初始化ca
// func getTLSConfig() (*tls.Config, error) {
// if _tlsConfig != nil {
// return _tlsConfig, nil
// }
// // load cert
// cert, err := tls.LoadX509KeyPair(wechatCertPath, wechatKeyPath)
// if err != nil {
// return nil, err
// }
// // load root ca
// caData, err := ioutil.ReadFile(wechatCAPath)
// if err != nil {
// return nil, err
// }
// pool := x509.NewCertPool()
// pool.AppendCertsFromPEM(caData)
// _tlsConfig = &tls.Config{
// Certificates: []tls.Certificate{cert},
// RootCAs: pool,
// }
// return _tlsConfig, nil
// }
// //携带ca证书的安全请求
// func SecurePost(url string, xmlContent []byte) (*http.Response, error) {
// tlsConfig, err := getTLSConfig()
// if err != nil {
// return nil, err
// }
// tr := &http.Transport{TLSClientConfig: tlsConfig}
// client := &http.Client{Transport: tr}
// return client.Post(
// url,
// "application/xml",
// bytes.NewBuffer(xmlContent))
// }
Loading…
Cancel
Save