예제 #1
0
func (c Client) New(params *pingpp.ChargeParams) (*pingpp.Charge, error) {
	start := time.Now()
	paramsString, errs := pingpp.JsonEncode(params)
	if errs != nil {
		if pingpp.LogLevel > 0 {
			log.Printf("ChargeParams Marshall Errors is : %q\n", errs)
		}
	}
	if pingpp.LogLevel > 2 {
		log.Printf("params of charge request to pingpp is :\n %v\n ", string(paramsString))
	}

	charge := &pingpp.Charge{}
	errch := c.B.Call("POST", "/charges", c.Key, nil, paramsString, charge)
	if errch != nil {
		if pingpp.LogLevel > 0 {
			log.Printf("%v\n", errch)
		}
		return nil, errch
	}
	if pingpp.LogLevel > 2 {
		log.Println("Charge completed in ", time.Since(start))
	}
	return charge, errch

}
예제 #2
0
func (c Client) New(params *pingpp.RedEnvelopeParams) (*pingpp.RedEnvelope, error) {
	paramsString, errs := pingpp.JsonEncode(params)
	if errs != nil {
		if pingpp.LogLevel > 0 {
			log.Printf("ChargeParams Marshall Errors is : %q/n", errs)
		}
		return nil, errs
	}
	if pingpp.LogLevel > 2 {
		log.Printf("params of redEnvelope request to pingpp is :\n %v\n ", string(paramsString))
	}
	redEnvelope := &pingpp.RedEnvelope{}
	err := c.B.Call("POST", "/red_envelopes", c.Key, nil, paramsString, redEnvelope)
	return redEnvelope, err
}
예제 #3
0
/**
 * 生成微信公众号 js sdk signature
 * @param charge Charge
 * @param jsapi_ticket string
 * @param urls string  当前页面的 url, 必须要动态获取
 * @return signatrue []byte
 */
func GetSignature(charge *pingpp.Charge, jsapi_ticket string, urls string) (signatrue []byte) {
	var wx Wx_pub
	a := charge.Credential
	m := a["wx_pub"]
	s, _ := pingpp.JsonEncode(m)
	pingpp.JsonDecode(s, &wx)
	jsapi_tickets := "jsapi_ticket=" + jsapi_ticket
	nonce_str := "noncestr=" + wx.NonceStr
	time_stamp := "timestamp=" + wx.TimeStamp
	urls = "url=" + urls
	signs := jsapi_tickets + "&" + nonce_str + "&" + time_stamp + "&" + urls
	h := sha1.New()
	h.Write([]byte(signs))
	signatrue = h.Sum(nil)
	return signatrue
}
예제 #4
0
func (c Client) New(ch string, params *pingpp.RefundParams) (*pingpp.Refund, error) {

	paramsString, errs := pingpp.JsonEncode(params)

	if errs != nil {
		if pingpp.LogLevel > 0 {
			log.Printf("RefundParams Marshall Errors is : %q\n", errs)
		}
		return nil, errs
	}
	if pingpp.LogLevel > 2 {
		log.Printf("params of refund request to pingpp is :\n %v\n ", string(paramsString))
	}
	refund := &pingpp.Refund{}
	err := c.B.Call("POST", fmt.Sprintf("/charges/%v/refunds", ch), c.Key, nil, paramsString, refund)
	return refund, err
}