import AP.Common.GDT;
import AP.FO.BusinessPartner.Global;
[Extension] businessobject AP.FO.BusinessPartner.Global:Customer {
// root node of Customer is not extendable
node Common {
[Label("Wechat ID")] element WechatID:LANGUAGEINDEPENDENT_EXTENDED_Text;
}
}
import ABSL;
var common = this.Common.GetFirst();
if( common.WechatID.IsInitial()) {
common.WechatID = common.Person.Name.FamilyName;
}
function notifyWechatUser(uuid,res){
console.log("begin to read uuid: " + uuid);
_getAccount(uuid).then(function(wechatID){
res.status(200).end();
sendMessage(wechatID, "Dear user, A kind reminder: your C4C account is changed in the system.");
});
}
function _getAccount(uuid) {
var AccountBOguid = uuid;
var detailODataUrl = config.indivudualCustomerNewurl;
var parentID = 'ParentObjectID eq \'' + AccountBOguid + '\'';
detailODataUrl = detailODataUrl + encodeURI(parentID);
var getOptions = {
url: detailODataUrl,
method: "GET",
json:true,
headers: {
"content-type": "application/json",
'Authorization': 'Basic ' + new Buffer(config.credential).toString('base64')
}
};
return new Promise(function(resolve,reject){
var requestC = request.defaults({jar: true});
console.log("request with url: " + detailODataUrl);
requestC(getOptions,function(error,response,body){
var wechatID = body.d.results[0].WechatID;
console.log("wechat id: " + wechatID);
resolve(wechatID);
}); // end of requestC
});
}
var config = require("../../config.js");
var request = require("request");
function printObject(oData){
for( var a in oData){
console.log("key: " + a);
console.log("value: " + oData[a]);
if( typeof oData[a] === "object"){
printObject(oData[a]);
}
}
}
function sendWCMeaasge(toUser,sMessage){
console.log("begin to send message to user: " + toUser + " with message: " + sMessage);
var options = {
url:"https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" +
config.accessToken,
method: "POST",
json:true,
headers: {
"content-type": "application/json"},
body:{
"touser":toUser,
"msgtype":"text",
"text":
{
"content":sMessage
}
}
};
request(options,function(error,response,data){
console.log("error? " + error);
console.log("response: " + response);
console.log("data: " + data);
console.log("response...............................................");
//printObject(response);
console.log("data.....................................................");
console.log("Status message: " + response.statusMessage);
console.log("Data: " + data.errmsg);
});
}
module.exports = sendWCMeaasge;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
4 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |