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

怀柔高端网站建设电商网站建设技术

怀柔高端网站建设,电商网站建设技术,万网建设网站,seo优化在哪里学主要是对代码进行了优化 上一个版本写死了帐号跟密码 #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.hkea.cn/news/14262645/

相关文章:

  • 锤子手机网站模板做美食哪些类型网站
  • python 网站开发 用什么框架网络营销成功案例
  • 手机产品网站建设成品网站1688入口网页版
  • 网站建设整体设计流程品牌网站建设开发价格
  • 网站建设与制作这个行业怎么样呢wordpress的阅读量
  • 承接做网站公司网站建设费用怎么入账
  • 建设银行手机登陆网站抖音代运营方案范文
  • 怎么给公司做简单网站android直播app开发
  • 做网站要属于无形资产吗wordpress思维导图
  • 专门做产品定制的网站网站关键词优化费用
  • 网站icp备案 去哪做网站一班需要多少钱
  • a3网站建设重庆seo代理价格
  • 网站程序更换彩票网站开发需要多少钱
  • 手机网站怎么做单页面最方便建立网站
  • 正规代做毕业设计的网站公司做分享网站好吗
  • 石碣网站仿做上海高端网站
  • 做企业网站安装什么系统好dw如何发布网页
  • 网站代理公司论坛前端模板
  • 网站pv多少可以云南旅游网站建设公司
  • 有哪些可以做外链的网站我的企业网站怎么seo
  • 东莞大朗网站建设公司东营新闻最新消息
  • 长沙岳麓区网站网络排名优化方法
  • 扬中网站开发wordpress导入大小.h
  • 国外网站开发发展历程衡水专业制作网站
  • 新手容易上手的cms做企业网站西丽网站建设
  • html5做静态网站用wordpress开发网站模板
  • 小学学校网站设计模板网上推广找xiala5徵
  • seo快速提高网站转化率上海广告公司联系方式
  • 全国最大的网站建设公司排名甘肃省住房和城乡建设厅网站
  • asp源码网站医院网站开发违法吗