| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2416 人关注过本帖
标题:与钉钉聊天工具的交互
只看楼主 加入收藏
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:293
专家分:38
注 册:2010-12-23
结帖率:58.75%
收藏
已结贴  问题点数:20 回复次数:18 
与钉钉聊天工具的交互
钉钉有一个DLL 用C#可以,在VFP中要如何使用这个DLL!请高手指点,附DLL
TopSdk.rar (664.66 KB)
用到这几个方法(我只会C#的)
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2021-12-1 13:54编辑过]

搜索更多相关主题的帖子: 交互 DLL C# 方法 聊天工具 
2021-12-01 13:50
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10606
专家分:43182
注 册:2014-5-20
收藏
得分:5 
1、贴代码
2、DLL怎样用
3、要有 标识key 和 密钥 才能测试
2021-12-01 15:30
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:293
专家分:38
注 册:2010-12-23
收藏
得分:0 
        //----  钉钉相关 开始 ------//
        public class HelperTools
        {

            string DingAppkey = "dingAAAAAAr4jrr";//钉钉  应用的唯一标识key
            string DingAppsecret = "Rdh-1XL5MmTsBBBBBBhY9EHqEgwkVi_kOQzORtIO7BsHiXLZ4yP4fjh1CzR";//钉钉  应用的密钥
            public static string dingAccessToken = ""; //钉钉接口调用凭证
                                                                 // <summary>
                                                                 /// 调用钉钉的api需要一个AccessToken,我们先获取这个AccessToken。
                                                                 /// </summary>
                                                                 /// <returns></returns>
            public string GetDingAccessToken()
            {
                string access_token = string.Empty;
                try
                {
                    string accessToken = string.Empty;
                    DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.);
                    OapiGettokenRequest request = new OapiGettokenRequest();
                    request.Appkey = DingAppkey;//钉钉  应用的唯一标识key
                    request.Appsecret = DingAppsecret;//钉钉  应用的密钥
                    request.SetHttpMethod("GET");
                    OapiGettokenResponse response = client.Execute(request);
                    access_token = response.AccessToken;
                }
                catch (Exception ex)
                {


                }
                return access_token;
            }
            /// <summary>
            /// 指定Post地址使用Get 方式获取全部字符串
            /// </summary>
            /// <param name="url">请求后台地址</param>
            /// <returns></returns>
            public string Post(string url, Dictionary<string, string> dic)
            {
                string result = "";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                #region 添加Post 参数
                StringBuilder builder = new StringBuilder();
                int i = 0;
                foreach (var item in dic)
                {
                    if (i > 0)
                        builder.Append("&");
                    builder.AppendFormat("{0}={1}", item.Key, item.Value);
                    i++;
                }
                byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
                req.ContentLength = data.Length;
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(data, 0, data.Length);
                    reqStream.Close();
                }
                #endregion
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                Stream stream = resp.GetResponseStream();
                //获取响应内容
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    result = reader.ReadToEnd();
                }
                return result;

            }

            /// <summary>
            /// 发送Get请求
            /// </summary>
            /// <param name="url">地址</param>
            /// <param name="dic">请求参数定义</param>
            /// <returns></returns>
            public string Get(string url, Dictionary<string, string> dic)
            {
                string result = "";
                StringBuilder builder = new StringBuilder();
                builder.Append(url);
                if (dic.Count > 0)
                {
                    builder.Append("?");
                    int i = 0;
                    foreach (var item in dic)
                    {
                        if (i > 0)
                            builder.Append("&");
                        builder.AppendFormat("{0}={1}", item.Key, item.Value);
                        i++;
                    }
                }
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
                //添加参数
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                Stream stream = resp.GetResponseStream();
                try
                {
                    //获取内容
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        result = reader.ReadToEnd();
                    }
                }
                finally
                {
                    stream.Close();
                }
                return result;

            }
        }
        //------  钉钉相关 结束 ------//
2021-12-01 20:45
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:293
专家分:38
注 册:2010-12-23
收藏
得分:0 
使用的时候这样:
            HelperTools tool = new HelperTools();
            string ldata = "0250452735598104";
            //这个是发送请求的接口 发送消息
            Dictionary<string, string> list = new Dictionary<string, string>();
            string url = "https://oapi. + tool.GetDingAccessToken().ToString();
            list.Add("agent_id", "1383998721");
            list.Add("userid_list", ldata); //"31192441281231555A, 0250452735598104B"
            list.Add("dept_id_list", "1");
            list.Add("to_all_user", "false");//这个false 可以针对单个部门 或者单个人,如果设成true 就是对全公司的发信息
            string Msg = "{\"msgtype\": \"text\",\"text\": {\"content\": \"生产完工确认:" + DateTime.Now.ToString() + "\"}}";
            list.Add("msg", Msg);
            //这是返回调用接口的结果
            string msg = tool.Post(url, list);
2021-12-01 20:51
加菲猫的VFP
Rank: 2
等 级:禁止访问
帖 子:31
专家分:16
注 册:2021-11-24
收藏
得分:5 
可以调用webapi来处理。目前加菲猫这里有付费开发和技术支持。

公众号:加菲猫的VFP
主页:http://www.
VFP搞定BS、CS、APP、公众号、中间层
2021-12-02 08:26
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10606
专家分:43182
注 册:2014-5-20
收藏
得分:0 
看提供的代码主要是GET和POST请求,好象没看到与这个DLL相关的地方?
GET请求还需要corpid ?
2021-12-02 09:07
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:293
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 6楼 吹水佬
new DefaultDingTalkClient("https://oapi.);
new OapiGettokenRequest();
OapiGettokenResponse response = client.Execute(request);
这三个地方都是用到那个DLL
2021-12-02 09:23
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10606
专家分:43182
注 册:2014-5-20
收藏
得分:0 
回复 7楼 laibinhua
那就先说说这个是什么DLL,怎么使用? 最好能提供使用和开发手册
2021-12-02 09:37
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10606
专家分:43182
注 册:2014-5-20
收藏
得分:0 
如果只是GET或POST请求,VFP可以不需要这个DLL
2021-12-02 09:38
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:293
专家分:38
注 册:2010-12-23
收藏
得分:0 
确实,刚看看了下文档,不需用用DLL,直接用post get 也可以实现,vfp的post get方法是?
2021-12-02 09:59
快速回复:与钉钉聊天工具的交互
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028607 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved