예제 #1
0
        /// <summary>
        /// 向管理员发送请求用户所需要的验证码
        /// </summary>
        /// <param name="toUser">请求的用户</param>
        /// <param name="MstType">消息类型:1 成绩录入,2 退款申请</param>
        private ResultModel SendCodeMsg(Sys_User toUser, string OrderID, int CodeType, string ReturnUrl = "")
        {
            try
            {
                var USVC = new UserService();
                var CSVC = new CodeService();

                var telephone = ConfigurationManager.AppSettings["ManagerPhone"].ToString();
                var codeStr   = CSVC.CreateCode(toUser.TelePhone, CodeType);
                var baseUser  = USVC.GetUserBaseByTelePhone(telephone);

                if (baseUser != null && !string.IsNullOrEmpty(codeStr))
                {
                    var first    = string.Empty;
                    var keyword1 = string.Empty;
                    var remark   = string.Empty;
                    if (CodeType == 1)
                    {
                        first    = string.Format(@"用户 {0} 正在进行成绩录入,向您请求验证码。", string.IsNullOrEmpty(toUser.TelePhone) ? toUser.UserName : toUser.TelePhone);
                        keyword1 = "成绩录入";
                        remark   = "验证码5分钟内有效!";

                        Common.WxPay.JsApiPay.SendMsg(baseUser.WeiXin_Openid, Common.WxPay.Lib.MsgConfig.Msg3, new
                        {
                            first = new Common.WxPay.Lib.MsgValue()
                            {
                                value = first
                            },
                            keyword1 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = keyword1
                            },
                            keyword2 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = codeStr
                            },
                            remark = new Common.WxPay.Lib.MsgValue()
                            {
                                value = remark
                            },
                        });
                    }
                    else
                    {
                        first    = string.Format(@"用户 {0} 提交了一条退款申请,请尽快处理。", string.IsNullOrEmpty(toUser.TelePhone) ? toUser.UserName : toUser.TelePhone);
                        keyword1 = "退款申请";
                        var recordEntity = new RecordService().SelectByID(OrderID);
                        remark = string.Format(@"订单编号 {0}", recordEntity.OrderNo);

                        ReturnUrl = string.Format(@"{0}/User/ValidateRefund?OrderID={1}&TelePhone={2}&CodeStr={3}",
                                                  PayConfig.WebSiteDomain(), OrderID, toUser.TelePhone, codeStr);

                        Common.WxPay.JsApiPay.SendMsg(baseUser.WeiXin_Openid, Common.WxPay.Lib.MsgConfig.Msg4, new
                        {
                            first = new Common.WxPay.Lib.MsgValue()
                            {
                                value = first
                            },
                            keyword1 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = string.IsNullOrEmpty(toUser.TelePhone) ? toUser.UserName : toUser.TelePhone
                            },
                            keyword2 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = keyword1
                            },
                            keyword3 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = DateTime.Now.ToString("yyyy-MM-dd")
                            },
                            remark = new Common.WxPay.Lib.MsgValue()
                            {
                                value = remark
                            },
                        }, ReturnUrl);
                    }


                    // 验证码发送过一次之后,就设为失效,5分钟之内不再重复发送
                    CSVC.SetCodeInvalid(toUser.TelePhone, codeStr);
                    return(Common.MessageRes.OperateSuccess.SetResult("SUCCESS"));
                }

                return(Common.MessageRes.OperateFailed.SetResult(null));
            }
            catch (Exception ex)
            {
                return((Common.MessageRes.OperateException + ex.ToString()).SetResult(null));
            }
        }