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


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

搜索更多相关主题的帖子: 交互 DLL C# 方法 聊天工具 
2021-12-01 13:50
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分: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
帖 子:295
专家分: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
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 6楼 吹水佬
new DefaultDingTalkClient("https://oapi.);
new OapiGettokenRequest();
OapiGettokenResponse response = client.Execute(request);
这三个地方都是用到那个DLL
2021-12-02 09:23
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
确实,刚看看了下文档,不需用用DLL,直接用post get 也可以实现,vfp的post get方法是?
2021-12-02 09:59
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
钉钉提供的DLL 只是封装GetDingAccessToken()的方法用于取到access_token,开发文档里有直接get方法 https://oapi. 可以取到access_token
开放文档:
https://developers.
图片附件: 游客没有浏览图片的权限,请 登录注册

用:cUrl = "https://oapi.
oHttp = CREATEOBJECT("MSXML2.XMLHTTP")
oHttp.Open("GET", cUrl, .F.)
oHttp.Send()
cTxt = oHttp.ResponseText
thisform.edit1.Value=cTxt
VFP里我得到的返回值是JSON,像这样:{"errcode":0,"access_token":"d59be116bcf7321b955e50196e4e45fa","errmsg":"ok","expires_in":7200}
VFP里有什么方法取到access_token 返回值 d59be116bcf7321b955e50196e4e45fa

[此贴子已经被作者于2021-12-2 10:22编辑过]

2021-12-02 10:03
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 14楼 加菲猫的VFP
谢谢,大佬回复
2021-12-02 14:15
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 16楼 sam_jiang
VFP有VFP的便捷,我现在是能用VFP就不用C# JAVA!
2021-12-03 09:22
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:295
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 18楼 antony521
谢谢回复
2021-12-03 11:25
快速回复:与钉钉聊天工具的交互
数据加载中...
 
   



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

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