1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| package main
import ( "fmt" dev "github.com/pyihe/wechat-sdk" )
func main() { var appId, mchId, apiKey, apiSecret string
client := dev.NewPayer(dev.WithAppId(appId), dev.WithMchId(mchId), dev.WithApiKey(apiKey), dev.WithSecret(apiSecret))
param := dev.NewParam() param.Add("nonce_str", "yourNonceStr") param.Add("body", "yourBody") param.Add("out_trade_no", "yourOutTradeNo") param.Add("total_fee", 1) param.Add("spbill_create_ip", "yourIp") param.Add("notify_url", "yourUrl") param.Add("trade_type", "JSAPI") result, err := client.UnifiedOrder(param) if err != nil { handleErr(err) } appId, _ = result.GetString("apppid") prepayId, _ := result.GetString("prepay_id") param = dev.NewParam() param.Add("appId", appId) param.Add("timeStamp", time.Now().Unix()) param.Add("nonceStr", "nonceStr") param.Add("package", "prepay_id="+prepayId) param.Add("signType", "MD5") sign := param.Sign("MD5")
param = dev.NewParam() param.Add("nonce_str", "yourNonceStr") param.Add("bill_date", "yourDate") param.Add("bill_type", "ALL") param.Add("tar_type", "GZIP") err = client.DownloadBill(param, "./bill") if err != nil { handleErr(err) } result, err = client.GetUserPhoneForMini("code", "encryptedData", "iv") if err != nil { handleErr(err) } var phone string if countryCode := result.Get("countryCode"); countryCode != nil && countryCode.(string) == "86" { purePhone := result.Get("purePhoneNumber") phone = purePhone.(string) } else { phoneNumber := result.Get("phoneNumber") phone = phoneNumber.(string) } fmt.Printf("user phone is %s\n", phone) }
|