Esempio n. 1
0
        private void _CreateWXButtonsToWeiXin(string payload, Action success, Action <int, string> fail)
        {
            string createCustomMenuUrl1 = string.Format(GlobalManager.TheWeiXinAPIOfV1[GlobalManager.APIPOSTKey_Cmu_CreateCustomMenu], GlobalManager.TheServiceAccount.AccessToken);

            HttpAdapter.postSyncStr(createCustomMenuUrl1, payload, (ret1, res1) =>
            {
                int errCode1   = int.Parse(ret1.errcode.ToString());
                string errMsg1 = ret1.errmsg.ToString();
                if (errCode1 == 0)
                {
                    if (success != null)
                    {
                        success();
                    }
                }
                else if (errCode1 == 42001 || errCode1 == 41001)
                {
                    if (_RefreshAccessToken())
                    {
                        string createCustomMenuUrl2 = string.Format(GlobalManager.TheWeiXinAPIOfV1[GlobalManager.APIPOSTKey_Cmu_CreateCustomMenu], GlobalManager.TheServiceAccount.AccessToken);
                        HttpAdapter.postSyncStr(createCustomMenuUrl2, payload, (ret2, res2) =>
                        {
                            int errCode2   = int.Parse(ret2.errcode.ToString());
                            string errMsg2 = ret2.errmsg.ToString();
                            if (errCode2 == 0)
                            {
                                if (success != null)
                                {
                                    success();
                                }
                            }
                            else
                            {
                                if (fail != null)
                                {
                                    fail(errCode2, errMsg2);
                                }
                            }
                        }, (he) =>
                        {
                            if (fail != null)
                            {
                                fail(-99, he.Message);
                            }
                        });
                    }
                    else
                    {
                        if (fail != null)
                        {
                            fail(GlobalManager.ERR_RefreshAccessTokenFaild, "刷新AccessToken失败");
                        }
                    }
                }
                else
                {
                    if (fail != null)
                    {
                        fail(errCode1, errMsg1);
                    }
                }
            }, (he) =>
            {
                if (fail != null)
                {
                    fail(-99, he.Message);
                }
            });
        }
        public InvokeResult PushJuDouCourse(JuDouCourse judouCourse)
        {
            InvokeResult result = new InvokeResult {
                Success = true
            };

            if (judouCourse != null && !string.IsNullOrEmpty(judouCourse.RemoteUrl))
            {
                try
                {
                    //点播
                    string strSql = string.Format("select a.BeginTime,DATEADD(S,a.CourseDuration,a.BeginTime) EndTime,a.CourseFlag," +
                                                  " a.CourseInfo,c.DeviceCode From Pam_CourseSchedule a inner join Pam_Device b on a.DeviceId=b.DeviceId and " +
                                                  " a.StationId=b.StationId and b.Status=1 inner join Pub_Device c on b.DeviceId=c.DeviceId and c.Status=1 " +
                                                  " where a.Status=1 and a.StationId='{0}' and a.DeviceId in('{1}') and a.BeginTime>= '{2}' and BeginTime<='{3}'" +
                                                  " and CourseFlag=3 order by a.DeviceId,a.BeginTime asc", judouCourse.StationId,
                                                  string.Join("','", judouCourse.DeviceIds.Split(',')),
                                                  judouCourse.CourseBeginTime, judouCourse.CourseEndTime);
                    IList <StringObjectDictionary> dibbleCourseList = BuilderFactory.DefaultBulder().ExecuteNativeSqlForQuery(strSql);
                    //直播
                    strSql = string.Format("select a.BeginTime,DATEADD(S,a.CourseDuration,a.BeginTime) EndTime,a.CourseFlag,a.CourseInfo,c.DeviceCode" +
                                           " From (select MAX(Id) Id,BeginTime From Pam_CourseSchedule " +
                                           " where Status=1 and StationId='{0}' and CourseFlag=2 and BeginTime>= '{1}' and BeginTime<='{2}' " +
                                           " group by BeginTime) x inner join Pam_CourseSchedule a on x.Id=a.Id inner join Pam_Device b on a.DeviceId=b.DeviceId and " +
                                           " a.StationId=b.StationId and b.Status=1 inner join Pub_Device c on b.DeviceId=c.DeviceId and c.Status=1 " +
                                           " order by a.BeginTime asc", judouCourse.StationId, judouCourse.CourseBeginTime, judouCourse.CourseEndTime);
                    IList <StringObjectDictionary> liveCourseList = BuilderFactory.DefaultBulder().ExecuteNativeSqlForQuery(strSql);

                    IList <object> pushCourse = new List <object>();
                    string[]       stationDevices, courseInfo;
                    string         beginTime, endTime;
                    //点播
                    foreach (var item in dibbleCourseList)
                    {
                        stationDevices = ((string)item["DeviceCode"] ?? "").Split('-');
                        courseInfo     = ((string)(item["CourseInfo"] ?? "")).Split('|');
                        beginTime      = ((DateTime)item["BeginTime"]).ToString("s", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "+08:00";
                        endTime        = ((DateTime)item["EndTime"]).ToString("s", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "+08:00";
                        pushCourse.Add(new { begin = beginTime, end = endTime, bindId = stationDevices[0], uuid = new string[] { stationDevices[2] }, vod_url = new string[] { courseInfo[2] }, live_type = 3 }.ToStringObjectDictionary());
                    }
                    //直播
                    foreach (var item in liveCourseList)
                    {
                        stationDevices = ((string)item["DeviceCode"] ?? "").Split('-');
                        courseInfo     = ((string)(item["CourseInfo"] ?? "")).Split('|');
                        beginTime      = ((DateTime)item["BeginTime"]).ToString("s", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "+08:00";
                        endTime        = ((DateTime)item["EndTime"]).ToString("s", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "+08:00";
                        pushCourse.Add(new { begin = beginTime, end = endTime, bindId = stationDevices[0], uuid = new string[] { "all" }, vod_url = new string[] { courseInfo[2] }, live_type = 2 }.ToStringObjectDictionary());
                    }


                    HttpAdapter.postSyncStr(judouCourse.RemoteUrl, pushCourse.ToJson(), (ret, res) =>
                    {
                        if (string.IsNullOrEmpty((string)ret))
                        {
                            result.Success      = false;
                            result.ErrorMessage = (string)ret;
                        }
                    }, (he) =>
                    {
                        result.ErrorCode    = he.ErrorCode;
                        result.ErrorMessage = he.Message;
                    });
                }
                catch (Exception ex)
                {
                    result.Success      = false;
                    result.ErrorMessage = ex.ToString();
                }
            }

            return(result);
        }