/// <summary> /// 处理语音请求 /// </summary> /// <param name="requestMessage"></param> /// <returns></returns> public override IResponseMessageBase OnVoiceRequest(RequestMessageVoice requestMessage) { //var responseMessage = CreateResponseMessage<ResponseMessageMusic>(); ////上传缩略图 //var accessToken = AccessTokenContainer.TryGetAccessToken(appId, appSecret); //var uploadResult = MediaApi.UploadTemporaryMedia(accessToken, UploadMediaFileType.image, // Server.GetMapPath("~/Images/Logo.jpg")); ////设置音乐信息 //responseMessage.Music.Title = "天籁之音"; //responseMessage.Music.Description = "播放您上传的语音"; //responseMessage.Music.MusicUrl = "http://www.w3ccloud.com/Media/GetVoice?mediaId=" + requestMessage.MediaId; //responseMessage.Music.HQMusicUrl = "http://www.w3ccloud.com/Media/GetVoice?mediaId=" + requestMessage.MediaId; //responseMessage.Music.ThumbMediaId = uploadResult.media_id; //return responseMessage; try { string token = WeiXinUtils.tryGetAccessToken(); string wxMediaUrl = WxApiUrl.mediaDown(token, requestMessage.MediaId); string url = WeiXinUtils.downloadFile(wxMediaUrl, "/image-lib", Guid.NewGuid().ToString()); string path = System.AppDomain.CurrentDomain.BaseDirectory + @"image-lib\" + Guid.NewGuid().ToString() + "." + requestMessage.MsgType; ResponseMessageVoice responseMessage = CreateResponseMessage <ResponseMessageVoice>(); responseMessage.Voice.MediaId = requestMessage.MediaId; return(responseMessage); } catch (Exception e) { ResponseMessageText responseMessage = CreateResponseMessage <ResponseMessageText>(); responseMessage.Content = "您发送了一条语音信息,ID:" + requestMessage.MediaId + requestMessage.Recognition + "\r\n" + e.Message + "\r\n" + e.StackTrace; return(responseMessage); } }
public static UserInfo CurrentUser(string openId) { string accToken = WeiXinUtils.tryGetAccessToken(); return(WeiXinUtils.getJsonObject <UserInfo>(WxApiUrl.userInfo(accToken, openId))); }