Beispiel #1
0
        /// <summary>
        /// 调用JSAPI
        /// </summary>
        /// <param name="openid">用户对于公众号唯一标识</param>
        /// <param name="total_fee"></param>
        /// <returns></returns>
        public static JSApi_model JsPay(string openid, string total_fee, string oName)
        {
            JSApi_model model        = new JSApi_model();
            string      wxJsApiParam = "";
            double      money        = double.Parse(total_fee);
            int         truemoney    = (int)(money * 100);

            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
            {
                return(null);
            }
            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay();

            //JSAPI支付预处理
            try
            {
                //进行统一支付认证
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(oName, openid, truemoney);
                //获取H5调起JS API参数
                wxJsApiParam = jsApiPay.GetJsApiParameters();
                model        = wxJsApiParam.toJsonObject <JSApi_model>();
            }
            catch (Exception ex)
            {
                //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex + "下单失败,请返回重试" + "</span>");
                //submit.Visible = false;
            }
            return(model);
        }
 /// <summary>
 /// 调用JSAPI
 /// </summary>
 /// <param name="openid">用户对于公众号唯一标识</param>
 /// <param name="total_fee"></param>
 /// <returns></returns>
 public static JSApi_model JsPay(string openid,string total_fee,string oName)
 {
     JSApi_model model = new JSApi_model();
     string wxJsApiParam = "";
     double money = double.Parse(total_fee);
     int truemoney = (int)(money * 100);
     //检测是否给当前页面传递了相关参数
     if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
     {
         return null;
     }
     //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
     JsApiPay jsApiPay = new JsApiPay();
     //JSAPI支付预处理
     try
     {
         //进行统一支付认证
         WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(oName,openid, truemoney);
         //获取H5调起JS API参数       
         wxJsApiParam = jsApiPay.GetJsApiParameters(); 
         model = wxJsApiParam.toJsonObject<JSApi_model>();
     }
     catch (Exception ex)
     {
         //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex + "下单失败,请返回重试" + "</span>");
         //submit.Visible = false;
     }
     return model;
 }