示例#1
0
    public void WeiXinPay()
    {
        //M_OrderList orderMod = new M_OrderList();
        //orderMod = orderBll.SelModelByOrderNo(OrderNo);
        payMod = paymentBll.SelModelByPayNo(PayNo);
        //function.WriteErrMsg(DataConverter.CLng(payMod.MoneyPay * 100).ToString());
        // B_Payment payBll = new B_Payment();
        //payMod.PaymentNum = OrderNo;
        // payMod.PayNo = payBll.CreatePayNo();
        //payMod.UserID = mu.UserID;
        //payMod.Status = (int)M_Payment.PayStatus.NoPay;
        //payMod.Remark = orderMod.Ordermessage;
        //payMod.MoneyPay =Convert.ToDecimal(orderMod.Ordersamount);
        //payMod.MoneyReal = payMod.MoneyPay;
        //payMod.PaymentID = payBll.Add(payMod);

        //WXPayData签名存在但不合法,原因:金额为0
        //---------------------------------------------
        B_WX_APPID appBll = new B_WX_APPID();

        string code = Request.QueryString["code"];
        //M_WX_APPID appMod = new M_WX_APPID();//自行置入缓存,使用时取出
        //appMod.APPID = WxPayConfig.APPID;//"wx8af32f5bf73b2c81";
        //appMod.Secret = WxPayConfig.APPSECRET;//61c897f42cd3fcc1131f8f4fbafd3293
        //WxAPI wxapi = new WxAPI();
        WxAPI wxapi = WxAPI.Code_Get(1);
        //wxapi.AppId = appMod;

        string  resultStr = APIHelper.GetWebResult("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxapi.AppId.APPID + "&secret=" + wxapi.AppId.Secret + "&code=" + code + "&grant_type=authorization_code");
        JObject obj       = (JObject)JsonConvert.DeserializeObject(resultStr);

        string    urlReq1 = Request.Url.AbsoluteUri.ToString().Substring(0, Request.Url.AbsoluteUri.ToString().LastIndexOf('/'));
        WxPayData wxdata  = new WxPayData();

        wxdata.SetValue("out_trade_no", payMod.PayNo);
        wxdata.SetValue("body", "我点吧");
        wxdata.SetValue("total_fee", Convert.ToInt32(payMod.MoneyPay * 100));//DataConverter.CLng(payMod.MoneyPay * 100)
        wxdata.SetValue("trade_type", "JSAPI");
        wxdata.SetValue("notify_url", urlReq1 + "/Return/WxPayReturn.aspx");
        wxdata.SetValue("product_id", payMod.PaymentNum);
        wxdata.SetValue("openid", obj["openid"].ToString());
        wxdata.SetValue("nonce_str", nonceStr);
        WxPayData result = WxPayApi.UnifiedOrder(wxdata);

        if (result.GetValue("return_code").ToString().Equals("FAIL"))
        {
            function.WriteErrMsg("商户" + result.GetValue("return_msg"));
        }
        prepay_id = result.GetValue("prepay_id").ToString();
    }
示例#2
0
        public static M_WX_APPID WX_SelMyModel()
        {
            B_WX_APPID appBll = new B_WX_APPID();
            M_UserInfo mu     = new B_User().GetLogin();
            int        appid  = DataConvert.CLng(DBCenter.ExecuteScala("ZL_CommonModel", "SpecialID", "GeneralID=" + mu.SiteID));

            if (appid < 1)
            {
                return(null);
            }
            M_WX_APPID appMod = appBll.SelReturnModel(appid);

            return(appMod);
        }
示例#3
0
 private void SendMsg(Object info)
 {
     try
     {
         M_WxTextMsg reqMod = (M_WxTextMsg)info;
         System.Threading.Thread.Sleep(1000);//延迟1秒,避免先于欢迎消息
         M_WX_APPID appmod = new B_WX_APPID().GetAppByWxNo(reqMod.ToUserName);
         if (appmod == null)
         {
             throw new Exception("目标公众号[" + reqMod.ToUserName + "]不存在");
         }
         WxAPI.Code_Get(appmod).SendMsg(reqMod.FromUserName, "您好,欢迎关注氿度伞,成为氿度伞的用户,我们将竭诚为您服务。我们为大家提供导航借伞、还伞、转伞,圈子社交等服务。24小时免费用伞,倡导绿色出行。转伞一人,即得5元。氿度伞欢迎您的使用!祝您用伞愉快!");
     }
     catch (Exception ex) { ZLLog.L("微信多信息出错,原因:" + ex.Message); }
 }
示例#4
0
    private void SendMsg(Object info)
    {
        try
        {
            M_WxTextMsg reqMod = (M_WxTextMsg)info;
            System.Threading.Thread.Sleep(1000);//延迟1秒,避免先于欢迎消息
            M_WX_APPID appmod = new B_WX_APPID().GetAppByWxNo(reqMod.ToUserName);
            if (appmod == null)
            {
                throw new Exception("目标公众号[" + reqMod.ToUserName + "]不存在");
            }
            string     msgStr  = "";
            M_UserAPP  uappMod = new M_UserAPP();
            B_UserAPP  uappBll = new B_UserAPP();
            M_UserInfo mu      = new M_UserInfo();
            uappMod = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat");
            if (uappMod != null)
            {
                mu = buser.GetUserByUserID(uappMod.UserID);
                M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey.Replace("qrscene_", "")));
                if (mu != null && mu.UserID > 0)
                {
                    if (DataConvert.CLng(mu.ParentUserID) > 0)
                    {
                        msgStr = "您已绑定了推荐人不能重复绑定!";
                    }
                    else
                    {
                        if (mu.UserID == DataConvert.CLng(reqMod.EventKey.Replace("qrscene_", "")))
                        {
                            msgStr = "您扫描的是您自己的二维码!";
                        }
                        else
                        {
                            if (pmu != null && pmu.UserID > 0)
                            {
                                string err = "";
                                if (CheckParentUser(pmu.UserID, mu.UserID, ref err))
                                {
                                    mu.ParentUserID = pmu.UserID.ToString();
                                    if (buser.UpdateByID(mu))
                                    {
                                        msgStr = "您成功绑定了推荐人:" + pmu.TrueName + "!";
                                    }

                                    else
                                    {
                                        msgStr = "绑定推荐人失败!";
                                    }
                                }
                                else
                                {
                                    msgStr = "绑定推荐失败,错误信息:" + err;
                                }
                            }
                            else
                            {
                                msgStr = "绑定推荐失败,推荐人不存在!";
                            }
                        }
                    }
                }
                WxAPI.Code_Get(appmod).SendMsg(reqMod.FromUserName, msgStr);
            }
        }
        catch (Exception ex) { ZLLog.L("微信多信息出错,原因:" + ex.Message); }
    }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                B_WX_APPID wxBll  = new B_WX_APPID();
                B_Content  conBll = new B_Content();
                M_Payment  payMod = payBll.SelModelByPayNo(PayNo);
                if (payMod == null)
                {
                    function.WriteErrMsg("支付单不存在");
                }
                if (payMod.Status != (int)M_Payment.PayStatus.NoPay)
                {
                    function.WriteErrMsg("该订单不可付款");
                }
                M_OrderList orderMod = orderBll.SelModelByOrderNo(payMod.PaymentNum.Trim(','));
                if (orderMod.StoreID < 1)
                {
                    function.WriteErrMsg("订单未绑定店铺");
                }
                M_CommonData storeMod = conBll.SelReturnModel(orderMod.StoreID);
                if (storeMod == null)
                {
                    function.WriteErrMsg("店铺信息不存在");
                }
                appMod = wxBll.SelReturnModel(DataConverter.CLng(storeMod.SpecialID));
                if (appMod == null)
                {
                    function.WriteErrMsg("店铺未绑定微信");
                }
                //appMod = WxPayApi.Pay_GetByID(AppID);
                if (string.IsNullOrEmpty(appMod.APPID))
                {
                    throw new Exception("未设置APPID");
                }
                if (string.IsNullOrEmpty(appMod.Secret))
                {
                    throw new Exception("未指定Secret");
                }
                if (string.IsNullOrEmpty(appMod.Pay_AccountID))
                {
                    throw new Exception("未设置商户号");
                }
                if (string.IsNullOrEmpty(appMod.Pay_Key))
                {
                    throw new Exception("未设置支付Key");
                }

                //首次进入自动跳转获取支付code
                if (!State.Equals("redirect"))
                {
                    string siteurl = HttpUtility.UrlEncode(SiteConfig.SiteInfo.SiteUrl + "/PayOnline/wxpay_mp.aspx?payno=" + PayNo + "&appid=" + appMod.ID + "&SuccessUrl=" + SuccessUrl);
                    string url     = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appMod.APPID + "&redirect_uri=" + siteurl + "&response_type=code&scope=snsapi_userinfo&state=redirect#wechat_redirect";
                    Response.Redirect(url);
                }
                WeiXinPay();//统一下单,并填充预付单号
                timestr = WxAPI.HP_GetTimeStamp();
                string stringA        = "appId=" + appMod.APPID + "&nonceStr=" + WxAPI.nonce + "&package=prepay_id=" + prepay_id + "&signType=MD5&timeStamp=" + timestr;
                string stringSignTemp = stringA + "&key=" + appMod.Pay_Key;
                paySign = StringHelper.MD5(stringSignTemp).ToUpper();
            }
        }