示例#1
0
 protected void submit_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(auth_code.Text))
     {
         Response.Write("<script LANGUAGE='javascript'>alert('请输入授权码!');</script>");
         return;
     }
     if (string.IsNullOrEmpty(body.Text))
     {
         Response.Write("<script LANGUAGE='javascript'>alert('请输入商品描述!');</script>");
         return;
     }
     if (string.IsNullOrEmpty(fee.Text))
     {
         Response.Write("<script LANGUAGE='javascript'>alert('请输入商品总金额!');</script>");
         return;
     }
     //调用刷卡支付,如果内部出现异常则在页面上显示异常原因
     try
     {
         string result = WxPayApiBiz.MicroPay(body.Text, fee.Text, auth_code.Text);
         Response.Write("<span style='color:#00CD00;font-size:20px'>" + result + "</span>");
     }
     catch (WxPayException ex)
     {
         Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
     }
     catch (Exception ex)
     {
         Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
     }
 }
        public ActionResult MicroPayPage(string auth_code, string body, string fee)
        {
            var alertMsg = new AlertMsg(true);

            if (string.IsNullOrEmpty(auth_code))
            {
                alertMsg.IsSuccess = false;
                alertMsg.Message  += "请输入授权码!\n";
            }
            if (string.IsNullOrEmpty(body))
            {
                alertMsg.IsSuccess = false;
                alertMsg.Message  += "请输入商品描述!\n";
            }
            if (string.IsNullOrEmpty(fee))
            {
                alertMsg.IsSuccess = false;
                alertMsg.Message  += "请输入商品总金额!\n";
            }
            if (!alertMsg.IsSuccess)
            {
                return(Json(alertMsg));
            }
            //调用刷卡支付,如果内部出现异常则在页面上显示异常原因
            try
            {
                alertMsg.Message = WxPayApiBiz.MicroPay(body, fee, auth_code);
            }
            catch (WxPayException ex)
            {
                alertMsg.IsSuccess = false;
                alertMsg.Message   = ex.ToString();
            }
            catch (Exception ex)
            {
                alertMsg.IsSuccess = false;
                alertMsg.Message   = ex.ToString();
            }
            return(Json(alertMsg));
        }