Esempio n. 1
0
func (this *app) prepareOrder(src string) (map[string]string, error) {
	prepareOrder := &prepareOrder{}
	err := xml.Unmarshal([]byte(src), prepareOrder)
	if err != nil {
		return nil, err
	}

	if prepareOrder.ReturnCode == success {
		if prepareOrder.ResultCode == success {
			payInfo := make(map[string]string)
			payInfo["appid"] = this.AppId
			payInfo["partnerid"] = this.MchId
			payInfo["prepayid"] = prepareOrder.PrepayId
			payInfo["package"] = "Sign=WXPay"
			now := time.Now()
			payInfo["noncestr"] = utils.UUID()
			payInfo["timestamp"] = fmt.Sprintf("%d", now.UnixNano()/int64(time.Second))
			sign, err := this.sign(payInfo)
			if err != nil {
				return nil, err
			}
			payInfo["sign"] = sign
			return payInfo, nil
		} else {
			return nil, errors.New("支付失败,ResultCode : fail")
		}
	} else {
		return nil, errors.New("支付失败,,ReturnCode : fail")
	}
}
Esempio n. 2
0
func (this OrderBuilder) BuildForApp(orderNo, description string, price int64) Order {

	this["nonce_str"] = utils.UUID()
	this["out_trade_no"] = orderNo
	this["body"] = description
	this["total_fee"] = fmt.Sprintf("%d", price)
	this["spbill_create_ip"] = utils.LocalIP()
	this["trade_type"] = "APP"

	return Order(this)
}
Esempio n. 3
0
func (this OrderBuilder) BuildForSubscription(orderNo, description, openId string, price float64) Order {

	this["nonce_str"] = utils.UUID()
	this["out_trade_no"] = orderNo
	this["body"] = description
	this["total_fee"] = fmt.Sprintf("%d", price)
	this["spbill_create_ip"] = utils.LocalIP()
	this["trade_type"] = "JSAPI"
	this["openid"] = openId

	return Order(this)
}