'统一下单
Dim openId As String = Args(0) '参数一,用户公众号ID,JSAPI模式必须,已经网页授权获取到,可以正常支付了
Dim productId As String = Args(1) '参数二,业务订单id
Dim trade_type As String = Args(2) '参数三,下单类型:JSAPI--公众号支付?NATIVE--原生扫码支付?APP--app支付
Dim total_fee As Integer = Args(3) '参数四,支付金额
Dim req As WxPayData = Functions.Execute("GetWxPayData")
req.SetValue("body", "微信充值卡")
Dim dr As DataRow = DataTables(trade_type).Find("product_id='" & productId & "'")
Dim out_trade_no As String = req.GenerateOutTradeNo()
dr("out_trade_no") = out_trade_no
req.SetValue("out_trade_no", out_trade_no)
req.SetValue("total_fee", total_fee) '支付价格,以分为单位,301就是¥3.01
req.SetValue("trade_type", trade_type ) '支付类型,扫码为
req.SetValue("openid", openId) '用户关注公众号后微信分配的ID
req.SetValue("product_id", productId ) '上传二维码时指定的商品ID
req.SetValue("appid", Vars("appid")) '公众号appid
req.SetValue("mch_id", Vars("mchid")) '商户ID
req.SetValue("nonce_str", req.GenerateNonceStr)
Dim nurl As String = Vars("api_order_notifyurl")
req.SetValue("notify_url", nurl) '支付成功后商户后台服务接收支付结果通知的url
req.SetValue("spbill_create_ip", Vars("ip")) '调用api的设备的IP,一般是服务器公网IP
req.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")) '二维码有效开始时间,针对模式二
req.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")) '二维码有效结束时间,针对模式二
req.SetValue("sign", req.MakeSign)
Functions.Execute("logtext",req.ToXML)
Dim url As String = Functions.Execute("GetApiUrl","api_unifiedorder")
Functions.Execute("logtext","开始调用下单:" & url)
Dim hc As New HttpClient(url)
hc.C
hc.Timeout = 6
hc.Content = req.ToXML
Dim ret As String = hc.GetData()
req = Functions.Execute("GetWxPayData")
req.FromXml(ret)
dr("return_code") = req.GetValue("return_code")
dr("return_msg") = req.GetValue("return_msg")
If req.IsSet("appid") = False OrElse req.IsSet("mch_id") = False OrElse req.IsSet("prepay_id") = False Then
Functions.Execute("logtext","统一下单失败!" & ret)
Return False
End If
dr("openid") = req.GetValue("openid")
dr("total_fee") = req.GetValue("total_fee") '实际支付金额
dr("prepay_id") = req.GetValue("prepay_id")
dr("trade_type") = req.GetValue("trade_type")
dr("device_info") = req.GetValue("device_info")
dr("result_code") = req.GetValue("result_code")
dr("code_url") = req.GetValue("code_url")
dr("err_code") = req.GetValue("err_code")
dr("err_code_des") = req.GetValue("err_code_des")
dr.Save
Return True