上次作的CRM項目,雖然實現了報價轉訂單的功能,可是客戶仍是遇到使用不方便的問題,客戶的業務流程中,審覈報價的時候是須要提供銷售人員與客戶的聊天記錄截圖,這都是在手機上的,電腦操做不方便,並且每次提交了報價還要在微信上跟主管說一聲,因而他們就在釘釘上使用報價審批功能,但願能夠將釘釘的數據對接到系統內。html
流程是:銷售人員使用釘釘進行報價的審批,審批經過的報價會對接到系統並生成一個銷售單和對應的應收。
要實現這個功能,我使用了白碼平臺提供的API功能,第一次使用平臺的API功能,沒想到還提供了對接各大平臺封裝好的api,包括有釘釘、微信服務號、企業微信、微信支付。web
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); } } }
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 } }); } } }