企业内部开发
基础
连接微信
办公
会议
会议统计管理
企业内部开发
服务端API
会话内容存档
开发案例演示
开发案例演示
最后更新:2021/03/18

c版本so使用案例

#include "WeWorkFinanceSdk_C.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string>
using std::string;

// 私钥内容,示例
static const char* priKey = 
"-----BEGIN RSA PRIVATE KEY-----\n"
"MIIEogIBAAKCAQEAngIe+L+lJFQOWu+FtgWzTYcG+bQTANvgatpjM0CswTLR5oY+\n"
"IvpQ9X0EID3AEC0PyaatOgSvmvWCUQunZtA3lhdkdsJG1Nxe1FOOI+Q1qlgW/ykT\n"
"JkuJJv8qnd9HFdpkTkkAB3CxW5zGoYYtBlnp3G3mUhGXZ/6dIWQ4Wln4lJlUlxSe\n"
"Qv4YvDOGN2dWbIG79nL9YNKyk9yYgLop2O7XJGXgqCuV5CUz4jdxB5XCH3SzqFgJ\n"
"A36JguG5jD7ovFh7cL+yp1iTyF/+1woDARXXpIj+W6K3Skoo5cpt0BboPYu0EuCz\n"
"YQtfn+hUfkcS6kltnwSXUBFzrSLhjCkf5tY/LwIDAQABAoIBADxB8M/KPk9hYuwZ\n"
"BjQJbny1btqRauHb+HSnfkdQddFj8RppvY6XSYKlP4qQIgvJM4kicFN87/83e5Au\n"
"0pNp+pjZqO2FX3/T3rI4fy9+21xwJaz/XBcxnUdq7jSwrqpN1Azq2AD+YBTg7/sv\n"
"cUJHzeDLZJeNr+Dv/7p5PuhuAVehm3g+b0GwuWK2HieXAlRR240vn+dCZoq8ti6Y\n"
"jmcZcJ9E6urY/L3d5bqByN2SGSbgJav6VAQYf8vfOU+SeAXFunGUWasuS3tvQlMO\n"
"eEPW37oNAsKHkKDQcKAcPo59fwPdbPKE/5N/wKPsbN8nVYTqdzociQdZnNpG8DK2\n"
"SdE5ZzkCgYEA4S3mNaklMA0vNR20lSum68j4L0r57Q7pN0ATmItBhF5ihEbtLlAg\n"
"OsLsxQZ2XIzevsnvUvRKDi7pcu3u2VqlX/89aWOcTOyEyKGHCUPkkOr4+3m2cGtQ\n"
"WF676TtNcfj4yOyJ5gMmtld84yUwrHjHgvtP/L73MftHzssQFj0Qk20CgYEAs6Ka\n"
"kXLAHtKwB5R/knXmkCYnfRX/TqjhTVO3Hr2PvqojAmiuWmWp9YsXtbYDFpxQPOp0\n"
"Y1qosC1qW+pZCXgSlsjsdhJa3t2hhsF2SAWoy2QpAsuHWizHq9T8XFb14U/4PjBz\n"
"B9P1mf5c84Iox3tUnwKuBsNt8FOXwJRPnddsH4sCgYB2zpLR6SaXzb0El2G5+sgd\n"
"S3G28iYfb2iZIBO2vnKY9nugMxPdBaWbm1D1O02j0yeLHlxJNl8EULgXTXZh87Oh\n"
"jLfILShAZeJBQQhQWSP1WiR3+mXJtrUzivg2PHXGFoic6kBvvWXlew+HgQ3HUgpi\n"
"D1rKja87Dct7TiR0t09RmQKBgBspvWG9Dlwa089xnxDQjzrA6ju59c85Lkh5Hjmh\n"
"xHi6VWzp02OL9/VPQRiTG0hx/pgXg936OYPaejjH6QrLg1QVsdvwzpjgvqoX2wDt\n"
"CicnUCRCDoeOOes726VC6Q9W/ly5CsvmOz87/WY9ClmPxq38w7/2EUvD+DCAvMFL\n"
"b+gdAoGAUiY1xefNe4qnbQzJXpPUUcOGiJcl7r9HwrZx8tDwGgBg+/5zbwi/0TfH\n"
"YrIj86g+JHaMEQCcKko8H0KdQzzp1vNECNxOGvz8ckOrO+NsLzHOpZ4jhojV/vFg\n"
"FNl6PhOdUozqTYwrnszoO67a/jKS/rWQh5Ta2Y2K5sUNprk8Z1w=\n"
"-----END RSA PRIVATE KEY-----\n";

// rsa 解密函数,需企业自行实现
int RsaDecryptChatData(const string &encryptdata,const string &priKey,string &aeskey);

int main(int argc, char *argv[])
{
	int ret = 0;
	if (argc < 2)
	{
		printf("./sdktools 1 seq limit proxy passwd timeout\n");
		printf("./sdktools 2 fileid savefile proxy passwd timeout\n");
		printf("./sdktools 3 encrypt_key encrypt_msg\n");
		return -1;
	}

	// new sdk api
    WeWorkFinanceSdk_t* sdk = NewSdk();

	// init api
    ret = Init(sdk, "wwd08coe7d775abaaa","zJ6k0naVVQ--gt9PUSSEvs03zW_nlDVmjAkPOTAfrew");
    if (ret != 0) {

       printf("init sdk err ret:%d\n", ret);
	   return ret;
    }

    int type =  strtoul(argv[1], NULL, 10);
	if (type == 1)
	{
		uint64_t iSeq = strtoul(argv[2], NULL, 10);
		uint64_t iLimit = strtoul(argv[3], NULL, 10);
		uint64_t timeout = strtoul(argv[6], NULL, 10);        
        Slice_t* chatDatas = NewSlice();

		// getchatdata api
        ret = GetChatData(sdk, iSeq, iLimit, argv[4],argv[5], timeout, chatDatas);
        if (ret != 0) {
            printf("GetChatData err ret:%d\n", ret);
            return -1;
        }
        printf("GetChatData len:%d data:%s\n", chatDatas->len, GetContentFromSlice(chatDatas));
        FreeSlice(chatDatas);
	}
	else if (type == 2)
	{
		std::string index = "";
		uint64_t timeout = strtoul(argv[6], NULL, 10);        
		while(true){
			printf("index:%s\n",index.c_str());
			MediaData_t* media = NewMediaData();

			// getmediadata api
			ret = GetMediaData(sdk, index.c_str(), argv[2],argv[4],argv[5], timeout, media);

			if (ret != 0) {
				printf("GetMediaData err ret:%d\n", ret);
				FreeMediaData(media);
				return -1;
			}
			printf("content size:%d isfin:%d outindex:%s\n",GetDataLen(media),IsMediaDataFinish(media),GetOutIndexBuf(media));

			char file[200];
			snprintf(file, sizeof(file), "%s%s", "/home/qspace/upload/", argv[3]);
			FILE *fp = fopen(file, "ab+");
			printf("filename:%s \n", file);
			if (NULL == fp) {
				printf("open file err\n");
				return -1;
			}

			fwrite(GetData(media),GetDataLen(media), 1, fp);
			fclose(fp);

			if(IsMediaDataFinish(media)==1)
			{
				FreeMediaData(media);
				break;
			}
			else{
				// assign index value if not finish
				index.assign(GetOutIndexBuf(media));

				// need free media 
				FreeMediaData(media);
			}
		}
    } 	else if (type == 3) {
        Slice_t* msg = NewSlice();
        std::string encrypt_key;

		// rsa decrypt code .need do it by yourself
        int ret = RsaDecryptChatData(argv[2], priKey, encrypt_key);
        printf("Rsadecrypt key :%s ret :%d\n" ,encrypt_key.c_str(), ret);

		// decryptdata api
        ret = DecryptData(encrypt_key.c_str(), argv[3], msg);
        printf("chatdata :%s ret :%d\n" ,GetContentFromSlice(msg), ret);
		FreeSlice(msg);
    } else if(type == 4){
		Slice_t* msg = NewSlice();
		ret = DecryptData(argv[2], argv[3], msg);
		printf("chatdata :%s ret :%d\n" ,GetContentFromSlice(msg), ret);
	}
    DestroySdk(sdk);
	return ret;
}

 

java版本so使用案例

import com.tencent.wework.Finance;
import java.io.*;


public class sdkdemo {
    public static void main(String[] args){
        long sdk = Finance.NewSdk();
        System.out.println(Finance.Init(sdk,  "wwd08coe7d775abaaa","zJ6k0naVVQ--gt9PUSSEvs03zW_nlDVmjAkPOTAfrew"));
        String priKey = 
            "-----BEGIN RSA PRIVATE KEY-----\n" +
            "MIIEowIBAAKCAQEAjzJfnYgy8gI/UdR9OMzMh2/Svtz6ynPJdgqWX0qCm7361g04\n" +
            "Sz/g+aJGtqu8jRJNg3rxQhezoy5mc+//QDyL6sM0auASS+eWx2igxVahLhJEWef3\n" +
            "2woMrb+OHs6nJf2jBcfA494KvgkxSYXU84vl8UCHwUI839SLBSLWofb8ccFEmy9W\n" +
            "VSWY7EIUVV8pO8sLZ9uVWK1IrHHSrcGkx4SF913RDIxCTExj7bLqxNRklzWZgi3m\n" +
            "bYoIsTG6dmsGkmxagGPEtuVOI2UjpjQw1WyrN+6o+2+qpOIuoHKF5vGrPbQBL1jU\n" +
            "nshGs3MnwTWdxVOe+bw8a+VAqxpD5DlfdKamgQIDAQABAoIBAGNRbe3mPGeMVXyd\n" +
            "I6kUqrs5PPNyc2OdwVpk53z6QfJhZyu1iZjvmkuqWN9z59f0nNyXlePgapDAqwC4\n" +
            "sdJM7EKM17tU5HvPCc4O7ItSlYJN2yh8cnVy1+5ekOUfMeFwtPRaYpfpNowt9ghn\n" +
            "kZbGLlsRBddt6KjaUv3h9vnpQ5hlhU53slh+Zsdrsselpy0sTCF0ulVQgioZ6lzg\n" +
            "/Y61xCGxRWqq71UT/7EOZwIoD3NmLRZLE6vxm8uBrFvZZ5/jw9Z//8S+vgtRUgGj\n" +
            "/5v55ftTG+EOsaz2Zvt+jghkaEAchcyy5LyUv09Ir9eOYfjNAgeCk9dQv6E+2BiR\n" +
            "SvcUJEECgYEA5CvcoSpV66qC1T99/JqmqyTjORZ4ZKBJY9vos4uxNYfCbbhNJLDY\n" +
            "QAbCC234nBuKQ+3cVKkWtjBwfNp90mEmIoN6sYv+SdtVe2ofhJEqLMTiGyZPi2Iv\n" +
            "+vvRpFmiAUfWXqFzBy+3HSoTkRqbCytUIT7NXZZ3YwKbbIhyzABTzSkCgYEAoKlf\n" +
            "Gsn4rQEfmitAGJpuiSahih6KV3K+S9olnPbwd04YOw4u5UmouhyC7N0z2K8AO6zo\n" +
            "IkzCQtWQS1B1uaPE/stG7I/iy0CI6q46nSly5pajBBGQc+Y5ixRf23hEjGgca556\n" +
            "1pDyMs0Nb0J2AGDcr8olrbT1KwBvg8oWHOlA4ZkCgYAmC+pONXD+SwBl7qBjbqY8\n" +
            "A3qgGk8Y+GFEdXbn+XMjKfARu5mhdJuakYXpwfyiizUS/qaut0NCPfGD4Cr62Zgy\n" +
            "SRo8YMuWJSyr15ZJ1KrjrDDHtiutYkH959+dOBT7ga8NOH6lxB8Ujd+VYopX4nG0\n" +
            "2XQFFwHxUI36GwaJXcSbgQKBgEe4VERZNTHF9p2UASD6j62aGTLXP1qaVmj2ESRo\n" +
            "+B/KNPbn9fdVUoUChU/Hz4VDWg9JuLbXHUFIpQl5+ZPNj/tOM3MXKF8jh/t7m57d\n" +
            "CfX1+P+v95RFihqUFdabcb5cG5PPQ3bVbclP0FeCi7rPgrTWwMsypN91alKivAxb\n" +
            "9CLBAoGBALfb5SEupOoyIUetiWhOc1vlmP+71rJEXUEYwm0CMmfKZRW+I1A8qTE+\n" +
            "DVT6iUMVt6jj8L/YiMzjUh8y8HLcp4mlldzdfyjssZg6v2hABJcnID6o3DcTXA8k\n" +
            "8uMmaZZ0qY4oUzwgZa7bf/C//3mKlRUMoBYOT/LAksZlySIBXoST\n" +
            "-----END RSA PRIVATE KEY-----\n";

		long ret = 0;

        if (args[0].equals("1")) {
            int seq = Integer.parseInt(args[1]);
            int limit = Integer.parseInt(args[2]);
            long slice = Finance.NewSlice();
            ret = Finance.GetChatData(sdk, seq, limit, args[3], args[4], Integer.parseInt(args[5]), slice);
            if (ret != 0) {
                System.out.println("getchatdata ret " + ret);
                return;
            }
            System.out.println("getchatdata :" + Finance.GetContentFromSlice(slice));
            Finance.FreeSlice(slice);
        } else if (args[0].equals("2")) {

			String indexbuf = "";
			while(true){
				long media_data = Finance.NewMediaData();
				ret = Finance.GetMediaData(sdk, indexbuf, args[1], args[2], args[3], Integer.parseInt(args[4]), media_data);
				System.out.println("getmediadata ret:" + ret);
				if(ret!=0){
					return;
				}
				System.out.printf("getmediadata outindex len:%d, data_len:%d, is_finis:%d\n",Finance.GetIndexLen(media_data),Finance.GetDataLen(media_data), Finance.IsMediaDataFinish(media_data));
                try {
                    FileOutputStream outputStream  =new FileOutputStream(new File("/home/qspace/upload/media_data"),true);
                    outputStream.write(Finance.GetData(media_data));
                    outputStream.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }

				if(Finance.IsMediaDataFinish(media_data) == 1)
				{
					// need free media_data
					Finance.FreeMediaData(media_data);
					break;
				}
				else
				{
					indexbuf = Finance.GetOutIndexBuf(media_data);
					
					// need free media_data
					Finance.FreeMediaData(media_data);
				}
																																			             }
        }else if (args[0].equals("3")) {
			// notice!
			// // use prikey to decrpyt get args[1] by do it yourself
			
			long msg = Finance.NewSlice();
			ret = Finance.DecryptData(sdk,args[1] ,args[2], msg);
			if (ret != 0) {
			     System.out.println("getchatdata ret " + ret);
			         return;
			}
			System.out.println("decrypt ret:" + ret + " msg:" + Finance.GetContentFromSlice(msg));
			Finance.FreeSlice(msg);
		}
		else {
            System.out.println("wrong args " + args[0]);
        }
        Finance.DestroySdk(sdk);
    }
}
上一篇获取会话内容
下一篇常见问题解答
    本节内容
服务端API
基础
连接微信
办公
会议
会议统计管理
客户端API
小程序
基础
连接微信
办公
WECOM-JSSDK
JS-SDK
基础
连接微信
办公
更新日志
联系我们