@Chiang
2021-10-02T17:14:43.000000Z
字数 5922
阅读 907
企业微信
2021-10
<?php
function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
function http_get($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
// 获取access_token
// $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=corpid&corpsecret=corpsecret";
// 应用secret
// $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=corpid&corpsecret=corpsecret";
// $response = http_get($url);
// $jsoninfo = json_decode($response, true);
// echo "<pre>";
// var_dump($jsoninfo);die;
/*
array(4) {
["errcode"]=>
int(0)
["errmsg"]=>
string(2) "ok"
["access_token"]=>
string(214) "hD_6Is2FDFizoxeSrNVq2xfLS8JXWCZAqUTXBLOPM2g4TZPe_dptVBGnZ8tH_khhQ-BTFJrd5-vp7kX2azXbug_j-XJHNriG6_UO77awAOrCcwj6unRmKsXhiSaXsx40F7etkWdQJx6W0hor-1JLlOkYleTLew4P1aRVFrTSDPVCQ4Z4NWXGjfYN4m-lTHNQ_5Fh_fK3fLtDkYHBV8upwg"
["expires_in"]=>
int(7200)
}
*/
$access_token = "hD_6Is2FDFizoxeSrNVq2xfLS8JXWCZAqUTXBLOPM2g4TZPe_dptVBGnZ8tH_khhQ-BTFJrd5-vp7kX2azXbug_j-XJHNriG6_UO77awAOrCcwj6unRmKsXhiSaXsx40F7etkWdQJx6W0hor-1JLlOkYleTLew4P1aRVFrTSDPVCQ4Z4NWXGjfYN4m-lTHNQ_5Fh_fK3fLtDkYHBV8upwg";
/*
array(4) {
["errcode"]=>
int(0)
["errmsg"]=>
string(2) "ok"
["access_token"]=>
string(214) "NeIN8z19iZA9eCkIXxngtUOD1-27TwhDeu7iERqzPK3sIt6ScnLsDiNYrL1XhrPkCfsYgDubOwM9saP42BFqEw035yM_lXN4KGLCjGkzwYMnFIua5AGsTII-G72Htvdgs7fIdDWvlNL1rLqg0t-sLlRIXX-_At_5DW4dJXbGK4QFGqUZWkxyhn5zzNbSArsj5CRYmSF0Q9jNs9oJffFkRA"
["expires_in"]=>
int(7200)
}
*/
$access_tokenyy = "54K1fRAkPpQD-c_J7KBsdvLb34Pk7c1seyBpsyhFhMhbxrJNpf-0So-J4BzaydnEXFDrouEu9ZDDRUb39TT_lHf9bk3de5SB82AE9sWXbZrFeUTs6HGqn3Dd5q7cBojOZ57S-kmZGb4RipZ0p4hq8XISr3tGLM9aqxv2_3-pnqiXBgZG7rKXoPisz0QIp5bTE6d7yhrMjZO8hjh5ljarNg";
//参考文档:https://work.weixin.qq.com/api/doc/90000/90136/90506
//获取企业的jsapi_ticket
// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$access_token";
// $response = http_get($url);
// $jsoninfo = json_decode($response, true);
// echo "<pre>";
// var_dump($jsoninfo);die;
/*
array(4) {
["errcode"]=>
int(0)
["errmsg"]=>
string(2) "ok"
["ticket"]=>
string(86) "sM4AOVdWfPE4DxkXGEs8VB4023ffWqYKtJMsCkairdH61Hzb6ZP_KijzeYqKxxXms65JmSpQNC6HDyUzQdiRMA"
["expires_in"]=>
int(7200)
}
*/
$jsapiTicketweb = "sM4AOVdWfPE4DxkXGEs8VB4023ffWqYKtJMsCkairdH61Hzb6ZP_KijzeYqKxxXms65JmSpQNC6HDyUzQdiRMA";
//获取应用的jsapi_ticket
// $url = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token=$access_tokenyy&type=agent_config";
// $response = http_get($url);
// $jsoninfo = json_decode($response, true);
// echo "<pre>";
// var_dump($jsoninfo);die;
/*
array(4) {
["errcode"]=>
int(0)
["errmsg"]=>
string(2) "ok"
["ticket"]=>
string(24) "iqTxs+T4mCtEaQ5OAOYibQ=="
["expires_in"]=>
int(7200)
}
*/
$jsapiTicket = "SzjxS+qa3voGix3YB4YJZQ==";
$url = "http://zzdemo.zbserp.com/fazhansdk.php";
$cropId = 'wxec82c081d811bbf1';
$timestamp = time();
$nonceStr = createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$stringweb = "jsapi_ticket=$jsapiTicketweb&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signatureweb = sha1($stringweb);
$signature = sha1($string);
?>
<!DOCTYPE html>
<html>
<head>
<title>title</title>
<!-- <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script> -->
<script src="https://res.wx.qq.com/wwopen/js/jsapi/jweixin-1.0.0.js"></script>
</head>
<body>
<br>
<br>
<br>
<button
id="dianji"
title="title1"
desc="desc1"
url="https://work.weixin.qq.com/api/doc/90000/90136/94549"
imgUrl="https://wwcdn.weixin.qq.com/node/wwnl/wwnl/style/images/independent/index/v3style/WxContactPic1$df4a387c.png"
chatId="wrCEskDwAAss0HDLkCt6WqFdFbh4FamQ"
>点击</button>
<script type="text/javascript">
// wx.config({
// beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
// debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
// appId: '<?= $cropId; ?>',
// timestamp: '<?= $timestamp; ?>',
// nonceStr: '<?= $nonceStr; ?>',
// signature: '<?= $signatureweb; ?>',
// jsApiList: [
// 'openExistedChatWithMsg'
// ]
// });
// 阿亮chatID: wrCEskDwAAYxY_6e_joqCxzxCiJOKqUQ
// 发展chatID: wrCEskDwAAss0HDLkCt6WqFdFbh4FamQ
wx.agentConfig({
// beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
// debug: true,
corpid: '<?= $cropId; ?>', // 必填,企业微信的corpid,必须与当前登录的企业一致
agentid: '1000014', // 必填,企业微信的应用id (e.g. 1000247)
timestamp: '<?= $timestamp; ?>', // 必填,生成签名的时间戳
nonceStr: '<?= $nonceStr; ?>', // 必填,生成签名的随机串
signature: '<?= $signature; ?>',// 必填,签名,见附录-JS-SDK使用权限签名算法
jsApiList: ['openExistedChatWithMsg'], //必填,传入需要使用的接口名称
success: function(res) {
// 回调
// document.querySelector("#dianji").onclick = function(){
document.getElementById("dianji").onclick = function(){
var title = this.getAttribute("title");
var desc = this.getAttribute("desc");
var url = this.getAttribute("url");
var imgUrl = this.getAttribute("imgUrl");
var chatId = this.getAttribute("chatId");
wx.invoke("openExistedChatWithMsg", {
chatId: chatId,
msg: {
msgtype: "link",
link: {
title: title,
desc: desc,
url: url,
imgUrl: imgUrl
}
}
},function(res){
if (res.err_msg == "openExistedChatWithMsg:ok")
{
alert('fazhanok');
}else{
alert(res.err_msg);
}
}
);
};
},
fail: function(res) {
if(res.errMsg.indexOf('function not exist') > -1){
alert('版本过低请升级')
}else{
alert(res.errMsg);
}
}
});
// wx.ready(function () {
// document.querySelector("#dianji").onclick = function(){
// console.log('asdf');
// wx.invoke("openExistedChatWithMsg", {
// chatId: "wrCEskDwAAss0HDLkCt6WqFdFbh4FamQ"
// // msg: {
// // msgtype: "link",
// // link: {
// // title: "title1",
// // desc: "desc1",
// // url: "link1",
// // imgUrl: "imgurl1"
// // }
// // }
// },function(res){
// if (res.err_msg == "openExistedChatWithMsg:ok")
// {
// // alert('fazhanok');
// }
// }
// );
// };
// });
</script>
</body>
</html>