Ejemplo n.º 1
0
        /// <summary>
        /// 创建二维码
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
        /// <param name="expireSeconds">临时二维码有效时间,以秒为单位。永久二维码将忽略此参数</param>
        /// <param name="sceneId">场景值ID,临时二维码时为32位整型,永久二维码时最大值为1000</param>
        /// <param name="sceneStr">场景字符串,仅actionName为QR_LIMIT_STR_SCENE时有效</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <param name="actionName">二维码类型,当actionName为QR_LIMIT_STR_SCENE时,sceneId会被忽略</param>
        /// <returns></returns>
        public static CreateQrCodeResult Create(string accessTokenOrAppId, int expireSeconds, int sceneId, QrCode_ActionName actionName, string sceneStr = null, int timeOut = Config.TIME_OUT)
        {
            return(ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var urlFormat = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}";
                object data = null;

                switch (actionName)
                {
                case QrCode_ActionName.QR_SCENE:
                    data = new
                    {
                        expire_seconds = expireSeconds,
                        action_name = "QR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_id = sceneId
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_LIMIT_SCENE:
                    data = new
                    {
                        action_name = "QR_LIMIT_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_id = sceneId
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_LIMIT_STR_SCENE:
                    data = new
                    {
                        action_name = "QR_LIMIT_STR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_str = sceneStr
                            }
                        }
                    };
                    break;

                default:
                    //throw new ArgumentOutOfRangeException(nameof(actionName), actionName, null);
                    throw new ArgumentOutOfRangeException(actionName.GetType().Name, actionName, null);
                }

                return CommonJsonSend.Send <CreateQrCodeResult>(accessToken, urlFormat, data, timeOut: timeOut);
            }, accessTokenOrAppId));
        }
Ejemplo n.º 2
0
        public static async Task <CreateQrCodeResult> CreateAsync(string accessTokenOrAppId, int expireSeconds, int sceneId, QrCode_ActionName actionName, string sceneStr = null, int timeOut = Config.TIME_OUT)
        {
            return(await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
            {
                var urlFormat = Config.ApiMpHost + "/cgi-bin/qrcode/create?access_token={0}";
                object data = null;

                switch (actionName)
                {
                case QrCode_ActionName.QR_SCENE:
                    data = new
                    {
                        expire_seconds = expireSeconds,
                        action_name = "QR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_id = sceneId
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_LIMIT_SCENE:
                    data = new
                    {
                        action_name = "QR_LIMIT_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_id = sceneId
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_LIMIT_STR_SCENE:
                    data = new
                    {
                        action_name = "QR_LIMIT_STR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_str = sceneStr
                            }
                        }
                    };
                    break;

                case QrCode_ActionName.QR_STR_SCENE:
                    data = new
                    {
                        expire_seconds = expireSeconds,
                        action_name = "QR_STR_SCENE",
                        action_info = new
                        {
                            scene = new
                            {
                                scene_str = sceneStr
                            }
                        }
                    };
                    break;

                default:
                    //throw new ArgumentOutOfRangeException(nameof(actionName), actionName, null);
                    throw new ArgumentOutOfRangeException(actionName.GetType().Name, actionName, null);
                }

                return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync <CreateQrCodeResult>(accessToken, urlFormat, data, timeOut: timeOut).ConfigureAwait(false);
            }, accessTokenOrAppId).ConfigureAwait(false));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建二维码
        /// </summary>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="expireSeconds">临时二维码有效时间,以秒为单位。永久二维码将忽略此参数</param>
        /// <param name="sceneId">场景值ID,临时二维码时为32位整型,永久二维码时最大值为1000</param>
        /// <param name="sceneStr">场景字符串,仅actionName为QR_LIMIT_STR_SCENE时有效</param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <param name="actionName">二维码类型,当actionName为QR_LIMIT_STR_SCENE时,sceneId会被忽略</param>
        /// <returns></returns>
        public static CreateQrCodeResult Create(string accessTokenOrAppId, int expireSeconds, int sceneId, QrCode_ActionName actionName,string sceneStr =null, int timeOut = Config.TIME_OUT)
        {
            return ApiHandlerWapper.TryCommonApi(accessToken =>
            {
                var urlFormat = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}";
                object data = null;

                switch (actionName)
                {
                    case QrCode_ActionName.QR_SCENE:
                        data = new
                        {
                            expire_seconds = expireSeconds,
                            action_name = "QR_SCENE",
                            action_info = new
                            {
                                scene = new
                                {
                                    scene_id = sceneId
                                }
                            }
                        };
                        break;
                    case QrCode_ActionName.QR_LIMIT_SCENE:
                        data = new
                        {
                            action_name = "QR_LIMIT_SCENE",
                            action_info = new
                            {
                                scene = new
                                {
                                    scene_id = sceneId
                                }
                            }
                        };
                        break;
                    case QrCode_ActionName.QR_LIMIT_STR_SCENE:
                        data = new
                        {
                            action_name = "QR_LIMIT_STR_SCENE",
                            action_info = new
                            {
                                scene = new
                                {
                                    scene_str = sceneStr
                                }
                            }
                        };
                        break;
                    default:
                        //throw new ArgumentOutOfRangeException(nameof(actionName), actionName, null);
                        throw new ArgumentOutOfRangeException(actionName.GetType().Name, actionName, null);
                }

                return CommonJsonSend.Send<CreateQrCodeResult>(accessToken, urlFormat, data, timeOut: timeOut);
            }, accessTokenOrAppId);
        }