Beispiel #1
0
        /// <summary>
        /// 发送应用文本消息
        /// </summary>
        /// <returns></returns>
        public async Task <ServiceResult <WxEE_AppMsgTextMsgOutput> > PushTextMessage(WxEE_AppMsgTextMsgInput input)
        {
            input.CheckNull(nameof(WxEE_AppMsgTextMsgInput));
            input.guid.CheckEmpty(nameof(input.guid));
            input.userid.CheckEmpty(nameof(input.userid));
            input.content.CheckEmpty(nameof(input.content));

            //读取配置
            var wechatEEApp = _middleDB.WechatEeappConfig.FirstOrDefault(w => w.Guid == input.guid);

            if (wechatEEApp == null)
            {
                return(ServiceResult <WxEE_AppMsgTextMsgOutput> .Failed(StatusCodes.Status404NotFound, "微信配置获取失败,请联系系统客服"));
            }
            var token = _tokenService.GetAccessToken(new WxEE_AuthorizeAccessTokenInput {
                guid = input.guid
            });
            var text = new WxEE_PushAppTextMessage();

            text.agentid      = wechatEEApp.AgentId;
            text.touser       = input.userid;
            text.text.content = input.content;
            //发送
            var result = await WxEEContext.PushAppMessageAPI.SendAppMessage(token.data.access_token, text);

            return(ServiceResult <WxEE_AppMsgTextMsgOutput> .Success(new WxEE_AppMsgTextMsgOutput { invaliduser = result.invaliduser }));
        }
Beispiel #2
0
        /// <summary>
        /// 获取jssdk配置
        /// </summary>
        /// <param name="mid"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public ServiceResult <WxEE_JssdkConfigOutput> GetConfig(WxEE_JssdkConfigInput input)
        {
            try
            {
                input.CheckNull(nameof(WxEE_JssdkConfigInput));
                input.guid.CheckEmpty(nameof(input.guid));
                input.url.CheckEmpty(nameof(input.url));

                var config = new WxEE_JssdkConfigOutput();
                //时间戳
                config.time_stamp = WxContext.Common.GenerateTimeStamp();
                //随机字符
                config.nonce_str = WxContext.Common.GenerateNonceStr();
                //获取微信配置
                var wechatConfig = _middleDB.WechatEeappConfig.Select(s => new { s.Id, s.Guid, s.CorpId }).FirstOrDefault(w => w.Guid == input.guid);
                config.corpid = wechatConfig.CorpId;
                //token
                var token = _configService.GetAccessToken(new WxEE_AuthorizeAccessTokenInput {
                    guid = wechatConfig.Guid
                });
                if (token.code != StatusCodes.Status200OK)
                {
                    return(ServiceResult <WxEE_JssdkConfigOutput> .Failed(token.code, token.msg));
                }
                //jsapi_ticket
                var ticket = GetJsapiTicket(new WxEE_JssdkJsapiTicketInput {
                    guid = wechatConfig.Guid, access_token = token.data.access_token
                });
                //signature
                config.signature = WxContext.Common.GenerateSignature(config.time_stamp, config.nonce_str, ticket.data.jsapi_ticket, input.url);
                return(ServiceResult <WxEE_JssdkConfigOutput> .Success(config));
            }
            catch (Exception ex)
            {
                return(ServiceResult <WxEE_JssdkConfigOutput> .Exception(ex.Message));
            }
        }