Ejemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            string content = Content.Get(context);
            string apiKey  = APIKey.Get(context);
            string seKey   = SecretKey.Get(context);
            string title   = Title.Get(context);
            int    maxlen  = MaxLen.Get(context);

            try
            {
                var client = new Baidu.Aip.Nlp.Nlp(apiKey, seKey);
                // 修改超时时间
                client.Timeout = 60000;
                //设置可选参数
                var options = new Dictionary <string, object>
                {
                    { "title", title }
                };
                //带参数调用新闻摘要接口
                string result = client.NewsSummary(content, maxlen, options).ToString();
                Result.Set(context, result);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
            }
        }