当前位置: 首页 > news >正文

互联网网站解决方案广州网站开发制作

互联网网站解决方案,广州网站开发制作,百度广告怎么投放,小红书推广营销主要是对代码进行了优化 上一个版本写死了帐号跟密码 #xff0c;这一个帐本有户可以直接设置对相关的key以及secret如果设置错时#xff0c;在聊天中也会返回提示。注册帐号时同时也设置了key及secrete升级到了net.8.0导出APK#xff0c;上一个版本是导出abb.解决了变型问…主要是对代码进行了优化 上一个版本写死了帐号跟密码 这一个帐本有户可以直接设置对相关的key以及secret如果设置错时在聊天中也会返回提示。注册帐号时同时也设置了key及secrete升级到了net.8.0导出APK上一个版本是导出abb.解决了变型问题现在生成桌面系统也能正常显示。 注册界面 ?xml version1.0 encodingutf-8 ? ContentPage xmlnshttp://schemas.microsoft.com/dotnet/2021/mauixmlns:xhttp://schemas.microsoft.com/winfx/2009/xamlx:ClassAiChat.Views.RegPageShell.NavBarIsVisibleTruexmlns:mctclr-namespace:CommunityToolkit.Maui.Behaviors;assemblyCommunityToolkit.Mauixmlns:localclr-namespace:AiChat.Views;assemblyAiChatTitle注册Grid RowDefinitionsAuto,* Margin0,10,0,0VerticalStackLayout Padding10 VerticalOptionsCenter HorizontalOptionsFillAndExpandFrame BorderColorWhiteCornerRadius10HasShadowTrueMargin0,20,0,0ZIndex0Padding8Frame.ShadowShadow BrushBlackOffset20,20Radius10Opacity0.9 //Frame.ShadowStackLayout Padding10VerticalStackLayout Padding10 BackgroundColor{StaticResource White}Label TextAI CHATFontSize30FontAttributesBoldTextColor{StaticResource Cyan100Accent}FontFamilyConsolasPadding5/Label Textto continue! TextColor{StaticResource Cyan100Accent}FontSize14 Padding5FontAttributesBold //VerticalStackLayoutVerticalStackLayout Padding10Label FontFamilyConsolas Text手机号 TextColor{StaticResource Cyan100Accent} /Frame CornerRadius10 Padding3 Margin0,10,0,0VerticalStackLayoutEntry x:NamePhone Text{Binding Phone,ModeTwoWay} Margin5,0,0,0 Placeholder手机 FontSize14Entry.Behaviorslocal:PhoneNumberValidatorBehavior //Entry.Behaviors/Entry/VerticalStackLayout/FrameVerticalStackLayout Padding0 Margin0,5,0,0Label FontFamilyConsolas Text密码 TextColor{StaticResource Cyan100Accent} /Frame CornerRadius10 Padding3 Margin0,10,0,0Entry x:NamePassword Text{Binding Password,ModeTwoWay} Margin5,0,0,0 Placeholder密码6位数字 IsPasswordTrue FontSize14Entry.Behaviorslocal:PasswordValidatorBehavior //Entry.Behaviors/Entry/Frame/VerticalStackLayoutLabel FontFamilyConsolas Text文心一言API_KEY TextColor{StaticResource Cyan100Accent} /Frame CornerRadius10 Padding3 Margin0,10,0,0VerticalStackLayoutEntry x:NameAPI_KEY Text{Binding API_KEY,ModeTwoWay} Margin5,0,0,0 PlaceholderAPI_KEY FontSize14 //VerticalStackLayout/FrameLabel FontFamilyConsolas Text文心一言SECRET_KEY TextColor{StaticResource Cyan100Accent} /Frame CornerRadius10 Padding3 Margin0,10,0,0VerticalStackLayoutEntry x:NameSECRET_KEY Text{Binding SECRET_KEY,ModeTwoWay} Margin5,0,0,0 PlaceholderSECRET_KEY FontSize14 //VerticalStackLayout/FrameButton Margin0,20,0,0x:NameRegButtonClickedRegButton_ClickedText确定注册 VerticalOptionsCenterAndExpand BackgroundColor{StaticResource Cyan100Accent} HorizontalOptionsFillAndExpand/BoxView Color{StaticResource Cyan100Accent}Margin0,20,0,0HeightRequest2HorizontalOptionsFill /Grid Padding10 Margin0,10,0,0 InputTransparentFalseLabel FontFamilyConsolas InputTransparentFalseLabel.FormattedTextFormattedStringSpan Text返回 TextColor{StaticResource Cyan100Accent} /Span Text登陆 TextColor{StaticResource Cyan100Accent} //FormattedString/Label.FormattedTextLabel.GestureRecognizersTapGestureRecognizer TappedOnLoginLabelTapped //Label.GestureRecognizers/Label/GridGrid Padding10 Margin0,10,0,0 InputTransparentFalseLabel FontFamilyConsolas InputTransparentFalseLabel.FormattedTextFormattedStringSpan Text百度文言一心登陆获取 API_KEY SECRET_KEY TextColorRed //FormattedString/Label.FormattedTextLabel.GestureRecognizersTapGestureRecognizer TappedOnBaiduLabelTapped //Label.GestureRecognizers/Label/Grid/VerticalStackLayout/StackLayout/Frame/VerticalStackLayout/Grid /ContentPageusing System.Text.RegularExpressions; using System.Windows.Input; using static Microsoft.Maui.ApplicationModel.Permissions; namespace AiChat.Views {public class PhoneNumberValidatorBehavior : BehaviorEntry{protected override void OnAttachedTo(Entry entry){entry.TextChanged OnEntryTextChanged;base.OnAttachedTo(entry);}protected override void OnDetachingFrom(Entry entry){entry.TextChanged - OnEntryTextChanged;base.OnDetachingFrom(entry);}private void OnEntryTextChanged(object sender, TextChangedEventArgs args){if (!(sender is Entry entry))return;string phoneNumber args.NewTextValue;bool isValid Regex.IsMatch(phoneNumber, ^\d{11}$);// Set IsValid property on the associated entryentry.SetValue(IsValidProperty, isValid);}public static readonly BindableProperty IsValidProperty BindableProperty.CreateAttached(IsValid, typeof(bool), typeof(PhoneNumberValidatorBehavior), false);}public class PasswordValidatorBehavior : BehaviorEntry{protected override void OnAttachedTo(Entry entry){entry.TextChanged OnEntryTextChanged;base.OnAttachedTo(entry);}protected override void OnDetachingFrom(Entry entry){entry.TextChanged - OnEntryTextChanged;base.OnDetachingFrom(entry);}private void OnEntryTextChanged(object sender, TextChangedEventArgs args){if (!(sender is Entry entry))return;string password args.NewTextValue;bool isValid Regex.IsMatch(password, ^\d{6}$);// Set IsValid property on the associated entryentry.SetValue(IsValidProperty, isValid);}public static readonly BindableProperty IsValidProperty BindableProperty.CreateAttached(IsValid, typeof(bool), typeof(PasswordValidatorBehavior), false);}public partial class RegPage : ContentPage{public RegPage(){InitializeComponent();BindingContext this;}private async void OnLoginLabelTapped(object sender, EventArgs e){var nextPage new LoginPage();var navigation Application.Current.MainPage.Navigation;await navigation.PushAsync(nextPage);}private async void OnBaiduLabelTapped(object sender, EventArgs e){await Launcher.TryOpenAsync(new Uri(https://login.bce.baidu.com/));}protected override bool OnBackButtonPressed(){Application.Current.Quit();return true;}private async void RegButton_Clicked(object sender, EventArgs e){bool isPhoneValid (bool)Phone.GetValue(PhoneNumberValidatorBehavior.IsValidProperty);bool isPasswordValid (bool)Password.GetValue(PasswordValidatorBehavior.IsValidProperty);if (isPhoneValid isPasswordValid){if (string.IsNullOrEmpty(API_KEY.Text) || string.IsNullOrEmpty(SECRET_KEY.Text)){await DisplayAlert(确定, API_KEY SECRET_KEY 不能为空?, 确定); // 修改按钮标签为 确定return;}if (await DisplayAlert(确定, 确定增加吗?, 确定, 取消)) // 修改按钮标签为 确定 和 取消{await SecureStorage.SetAsync(PHONE, Phone.Text);await SecureStorage.SetAsync(PASSWORD, Password.Text);await SecureStorage.SetAsync(API_KEY, API_KEY.Text);await SecureStorage.SetAsync(SECRET_KEY, SECRET_KEY.Text);await DisplayAlert(成功, 注册成功, OK);}}else{await DisplayAlert(验证失改, 手机号密码错, OK);}}} }加入了手机号密码的验证同时要求加入API_KEYSECRET_KEY。 聊天代码 using System; using System.Collections.ObjectModel; using System.IO; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; namespace AiChat.Views {// 用于将文本颜色转换为视图颜色的转换器public class MessageColorConverter : IValueConverter{public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){// 根据“IsUser”的值确定文本颜色的逻辑bool isUser (bool)value;if (isUser){// 返回用户的文本颜色return Color.FromHex(#0000FF); // 更改为所需的颜色}else{// 返回其他情况的文本颜色return Color.FromHex(#000000);// 更改为所需的颜色}}public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){// 如果需要双向绑定请实现此方法进行转换throw new NotImplementedException();}}// 聊天页面类public partial class Chat : ContentPage{// 定义表示聊天消息的类public class ChatMessage{public string Text { get; set; }public bool IsUser { get; set; }public DateTime Timestamp { get; set; }}static string sAPI_KEY ;static string sSECRET_KEY ;// 用于存储聊天消息的集合private ObservableCollectionChatMessage chatMessages new ObservableCollectionChatMessage();// 构造函数public Chat(){InitializeComponent();// 将chatMessages集合绑定到CollectionView的ItemsSourcecollectionView.ItemsSource chatMessages;SetStoredValues();}// 获取 API_KEY SECRET_KEYprivate async void SetStoredValues(){var storedKey await SecureStorage.GetAsync(API_KEY);if (!string.IsNullOrEmpty(storedKey)){sAPI_KEY storedKey;}var storedSecret await SecureStorage.GetAsync(SECRET_KEY);if (!string.IsNullOrEmpty(storedSecret)){sSECRET_KEY storedSecret;}entryUserMessage.Text ;}// 发送消息按钮点击事件处理程序private async void SendMessage_Clicked(object sender, EventArgs e){try{sendmessageButton.IsEnabled false;loadingIndicator.IsVisible true;// 从Entry中获取用户的消息string userMessage entryUserMessage.Text;if (string.IsNullOrEmpty(userMessage) ){ return; }// 将用户的消息添加到chatMessages集合并添加时间戳chatMessages.Add(new ChatMessage{Text $您{userMessage},IsUser true,Timestamp DateTime.Now});// 模拟对方的响应string response await getAnswer(userMessage);response response ! null ? response : 请配置好文心一言的API_KEY SECRET_KEY;// 将对方的响应添加到chatMessages集合并添加时间戳chatMessages.Add(new ChatMessage{Text $AI{response},IsUser false,Timestamp DateTime.Now}); // 可选滚动到底部以显示最新的消息collectionView.ScrollTo(chatMessages[chatMessages.Count - 1], ScrollToPosition.End);// 发送后清除用户的输入entryUserMessage.Text string.Empty;}finally{// Hide the loading indicator when the operation is completeloadingIndicator.IsVisible false;sendmessageButton.IsEnabled true;}}public static async Taskstring getAnswer(string question){var url $https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/aquilachat_7b?access_token{await GetAccessToken()};var payload JsonConvert.SerializeObject(new{messages new[]{new { role user, content question }}});using (var client new HttpClient()){var content new StringContent(payload, Encoding.UTF8, application/json);var response await client.PostAsync(url, content);if (response.IsSuccessStatusCode){var responseContent await response.Content.ReadAsStringAsync();var dictObj JsonConvert.DeserializeObjectdynamic(responseContent);return dictObj.result;}else{Console.WriteLine($HTTP请求失败: {response.StatusCode});return 请配置好文心一言的API_KEY SECRET_KEY;}}}private static async Taskstring GetAccessToken(){var url https://aip.baidubce.com/oauth/2.0/token;using (var client new HttpClient()){var parameters new FormUrlEncodedContent(new[]{new KeyValuePairstring, string(grant_type, client_credentials),new KeyValuePairstring, string(client_id, sAPI_KEY),new KeyValuePairstring, string(client_secret, sSECRET_KEY)});var response await client.PostAsync(url, parameters);if (response.IsSuccessStatusCode){var content await response.Content.ReadAsStringAsync();var result JsonConvert.DeserializeObjectdynamic(content);return result.access_token;}else{Console.WriteLine($HTTP请求失败: {response.StatusCode});return wrong;}}}} } 桌面界面
http://www.pierceye.com/news/981668/

相关文章:

  • 论坛网站制作费用wordpress如何调用html代码
  • 打码兔怎么和网站做接口重庆网站建设找承越
  • 做海报的网站什么编辑器微楼书网站建设
  • 免费建站的网站能做影视网站吗深圳网站建设素材网站
  • 网页中网站设计规划流程wordpress主题
  • 贵阳百度做网站电话培训学校
  • 网站关键词推广哪家好深圳方维网络科技有限公司
  • 美工需要的网站阿里云wordpress托管
  • 医疗行业网站建设怎样在网上建立平台
  • 潍坊网站建设网超之梦做的网站后台修改栏目描述
  • 广西建设厅官网证件查询网站优化对企业有什么好处
  • 哪个网站做外贸的多济南建设信息网官网
  • 制作网站能挣钱企业宣传片策划公司
  • 临沂网站建设模板wordpress添加导航页面
  • 有关wordpress教学的网站商标注册号
  • 常用搜索网站浙江立鹏建设有限公司网站
  • 天津做网站优化的公司番禺商城网站建设
  • 网站建设大熊猫点搜营销型网站头部布局的元素
  • wordpress 网站死机淄博专业网站建设价格
  • 网站建设 招标书慈溪机械加工网
  • dede网站怎么做404页面做网站的市场有那么大吗
  • 自己做下载类网站家在深圳网页版
  • 建设银行网站个人客户传奇新服网
  • 河东手机网站建设工作服厂家联系方式
  • 站长工具seo综合查询搭建流程
  • 各省住房和城乡建设厅网站怎样租用个人网站空间
  • 深圳市南山区住房和建设局网站官网桂林两江四湖象山景区讲解导游词
  • 环保网站设计是什么柴沟堡做网站公司
  • 用php和mysql做网站wordpress怎么创建自己的博客
  • 网站建设制作设计珠海百度收录排名