コード例 #1
0
ファイル: WxMP_KfMsgService.cs プロジェクト: amwitx/Amw.Core
        /// <summary>
        /// 发送客服文本消息
        /// </summary>
        /// <param name="wid"></param>
        /// <param name="openid"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public async Task <ServiceResult <CommonResultStateOutput> > SendText(WxMP_KfMsgTextMsgInput input)
        {
            try
            {
                input.CheckNull(nameof(WxMP_KfMsgTextMsgInput));
                input.guid.CheckEmpty(nameof(input.guid));
                input.openid.CheckEmpty(nameof(input.openid));
                input.content.CheckEmpty(nameof(input.content));

                var token = _tokenService.GetAccessToken(new WxMP_AuthorizeAccessTokenInput {
                    guid = input.guid
                });
                if (token.code != 200)
                {
                    return(ServiceResult <CommonResultStateOutput> .Failed(StatusCodes.Status400BadRequest, token.msg));
                }
                var text = new WxMP_KfTextMessage();
                text.touser       = input.openid;
                text.text.content = input.content;
                var result = await WxMPContext.KfMessageAPI.SendKfMessage(token.data.access_token, text);

                return(ServiceResult <CommonResultStateOutput> .Success(new CommonResultStateOutput { result_state = result.errmsg }));
            }
            catch (Exception ex)
            {
                return(ServiceResult <CommonResultStateOutput> .Exception(ex.Message));
            }
        }
コード例 #2
0
        public async Task <ServiceResult <CommonResultStateOutput> > send_text(WxMP_KfMsgTextMsgInput input)
        {
            //逻辑
            var result = await _mp_push.SendText(input);

            Response.StatusCode = result.code;
            return(result);
        }