优秀的编程知识分享平台

网站首页 > 技术文章 正文

低代码开发,快速对接钉钉报价审批功能

nanyue 2025-03-04 13:21:57 技术文章 6 ℃

上次做的CRM项目,虽然实现了报价转订单的功能,但是客户还是遇到使用不方便的问题,客户的业务流程中,审核报价的时候是需要提供销售人员与客户的聊天记录截图,这都是在手机上的,电脑操作不方便,而且每次提交了报价还要在微信上跟主管说一声,于是他们就在钉钉上使用报价审批功能,希望可以将钉钉的数据对接到系统内,流程是:销售人员使用钉钉进行报价的审批,审批通过的报价会对接到系统并生成一个销售单和对应的应收。

要实现这个功能,我使用了平台提供的API功能,第一次使用白码平台的API功能,没想到还提供了对接各大平台封装好的api,包括有钉钉、微信服务号、企业微信、微信支付。



对接流程如下:

1.因为是由钉钉的流程触发系统的接口,所以需要设置一个回调接口(webhook),根据钉钉官方的开发文档,需要先注册回调,注册回调就需要用平台的云函数webhook了。根据平台提供的扩展库,写出如下注册回调的云函数和webhook,直接在平台上测试就能注册回调了。


async?function?run($input,$output,$modules?=?modules){
????let?dingTalkApi?=?$modules.dingTalkApi;
????let?registerCallBack?=?await?dingTalkApi.registerCallBack({
????????call_back_tag:["bpms_instance_change"],//审批状态变更回调
????????token:"",
????????aes_key:"",
????????url:""
????});
????$output.res?=?registerCallBack;
}


async?function?hook($req,$resp,$modules?=?modules){
????let?dingTalkApi?=?$modules.dingTalkApi;
????let?helper?=?$modules.helper;
????let?data?=?null;//收到的数据
????//用于验证钉钉回调
????let?token?=?await?helper.getConfig("token")
????let?aesKey?=?await?helper.getConfig("aesKey")
????let?corpid?=?await?helper.getConfig("corpid");
????let?{timestamp,nonce}?=?$req.query;
????let?result?=?dingTalkApi.instanceCrypto({
????????token,
????????encodingAESKey:aesKey,
????????CorpId:corpid,
????????timestamp,
????????nonce
????});
????$resp.body?=?result;
????//加密信息
????let?encrypt?=?$req.body.encrypt;
????if(encrypt){
????????let?msg?=?await?dingTalkApi.msgCrypt.decrypt(encrypt);
????????if(msg.message){
????????????data?=?JSON.parse(msg.message);
????????}
????}
}



2.注册好回调后,就需要调整webhook的代码逻辑了,因为之后钉钉的审批实例状态有变更时都会执行webhook的代码。


async?function?hook($req,$resp,$modules?=?modules){
????let?dingTalkApi?=?$modules.dingTalkApi;
????let?helper?=?$modules.helper;
????let?data?=?null;//收到的数据
????//用于验证钉钉回调
????let?token?=?await?helper.getConfig("token")
????let?aesKey?=?await?helper.getConfig("aesKey")
????let?corpid?=?await?helper.getConfig("corpid");
????let?{timestamp,nonce}?=?$req.query;
????let?result?=?dingTalkApi.instanceCrypto({
????????token,
????????encodingAESKey:aesKey,
????????CorpId:corpid,
????????timestamp,
????????nonce
????});
????$resp.body?=?result;
????//加密信息
????let?encrypt?=?$req.body.encrypt;
????if(encrypt){
????????let?msg?=?await?dingTalkApi.msgCrypt.decrypt(encrypt);
????????if(msg.message){
????????????data?=?JSON.parse(msg.message);
????????}
????}

????let?processCode?=?data.processCode;
????if(processCode?==?"PROC-C0640453-0814-4D29-9A11-B6DF548C57ED"){
????????let?processInstanceId?=?data.processInstanceId;//审批实例id
????????let?result?=?data.result;
????????let?type?=?data.type;
????????if(result?==?"agree"?&&?type?==?"finish"){
????????????//调用功能,生成订单和应收
????????????await?$modules.program.exec("5f471de7d67c5c69ae4f5b6c",{
????????????????"5eb9416bb75b4176eca49a17":{
????????????????????"5f471caa00d5f969b43eefb1":processInstanceId
????????????????}
????????????});
????????}
????}
}

3.当客户在钉钉上审批通过了一个报价后,就会触发这个webhook,webhook再调用功能来生成一个订单和应收,这个功能里也包含了调用API的步骤,根据审批实例id获取审批实例的详情,里面就包含了报价的信息,获取到报价信息就可以录入到系统中了。



4.测试结果




5.整个流程下来,结合了钉钉的流程管理和白码的数据处理功能,提高了整个销售团队的销售效率。

最近发表
标签列表