- 企业微信签名老是错误
//支付 $data['appid']=''; $data['mch_id']=''; $data['nonce_str']=unicode(); $data['openid']=$resopenid['openid']; $data['check_name']='NO_CHECK'; $data['amount']='1000'; $data['desc']='测试审批报销'; $data['spbill_create_ip']=$_SERVER['SERVER_ADDR']; $data['partner_trade_no']=partner_trade_no(); $data['ww_msg_type']='APPROVAL_MSG'; $data['approval_number']=$datas; $data['act_name']='内部报销'; //企业支付签名 $data=array_filter($data); ksort($data); $str_a=''; foreach($data as $k=>$v){ $str_a.=$k.'='.$v.'&'; } $str_a.='key='.'企业secrect'; $data['workwx_sign']=md5($str_a); //支付签名 ksort($data); $str=''; foreach($data as $k=>$v) { $str.=$k.'='.$v.'&'; } $str.='key='.$secrect_key; $data['sign']=md5($str); $xml=arraytoxml($data); // echo $xml; $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/paywwsptrans2pocket'; $res=curl($xml,$url); $return=xmltoarray($res); print_r($return); // echo getcwd().'/cert/apiclient_cert.pem';die; function unicode() { $str = uniqid(mt_rand(),1); $str=sha1($str); return md5($str); } function arraytoxml($data){ $str=''; foreach($data as $k=>$v) { $str.='<'.$k.'>'.$v.''; } $str.=''; return $str; } function xmltoarray($xml) { //禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring),true); return $val; } function curl($param="",$url) { $postUrl = $url; $curlPost = $param; $ch = curl_init(); //初始化curl curl_setopt($ch, CURLOPT_URL,$postUrl); //抓取指定网页 curl_setopt($ch, CURLOPT_HEADER, 0); //设置header curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_POST, 1); //post提交方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); // 增加 HTTP Header(头)里的字段 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 终止从服务端进行验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/cert/apiclient_cert.pem'); //这个是证书的位置 curl_setopt($ch,CURLOPT_SSLKEY,getcwd().'/cert/apiclient_key.pem'); //这个也是证书的位置 $data = curl_exec($ch); //运行curl curl_close($ch); return $data; } function curl_get_https($url){ $curl = curl_init(); // 启动一个CURL会话 curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在 $tmpInfo = curl_exec($curl); //返回api的json对象 //关闭URL请求 curl_close($curl); return $tmpInfo; //返回json对象 } function partner_trade_no(){ return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8); } 返回错误 Array( [return_code] => SUCCESS [return_msg] => Array ( ) [appid] => wwb455222360fa49c5 [mch_id] => 1226827102 [device_info] => Array ( ) [nonce_str] => c48014c9ce1284348e741ec7b128f2b9 [result_code] => FAIL [err_code] => WORKWX_SIGN_ERROR [err_code_des] => Array ( )
2021-01-08 - 通过api批量获取审批单号,userid和groupname为空
通过api批量获取审批数据,userid和groupname字段为空。其他的字段都是有数据的。 <?php include_once("wechat/api/src/CorpAPI.class.php"); include_once("wechat/api/src/ServiceCorpAPI.class.php"); include_once("wechat/api//src/ServiceProviderAPI.class.php"); $api = new CorpAPI('', ''); $start_time=strtotime('2020-12-01'); $end_time=strtotime('2020-12-31'); try { $ApprovalDataList = $api->ApprovalDataGet($start_time, $end_time); $arr=(json_encode($ApprovalDataList)); print_r(json_decode($arr,true)); } catch (Exception $e) { // echo $e->getMessage() . "\n"; } 返回的数据 [data] => Array ( [0] => Array ( [userid] => [groupname] => [checkin_type] => [exception_type] => [checkin_time] => [location_title] => [location_detail] => [wifiname] => [notes] => [wifimac] => [mediaids] => Array ( ) [spname] => 费用申请 [apply_name] => 员工姓名 [apply_org] => 房企事业部 [approval_name] => Array ( [0] => 老板A ) [notify_name] => Array ( [0] => 老板B ) [sp_status] => 2 [sp_num] => 202012010001 [apply_time] => 1606785418 [apply_user_id] => LaoBanA [comm] => Array ( [apply_data] => [{"id":"item-1494248811896","title":"报销类型","type":"select","value":"活动物料"},{"id":"Text-1606147433459","title":"报销事由","type":"text","value":"11月暖场活动"},{"id":"item-1494249104239","title":"费用金额","type":"number","value":"2500"},{"id":"item-1494249113679","title":"发生日期","type":"date","value":"1606752000000"},{"id":"Table-1605594320035","title":"明细","type":"list","value":[[{"id":"Text-1605594358538","title":"名称","type":"text","value":"报销内容"},{"id":"Number-1606147938838","title":"数量","type":"number","value":"1"},{"id":"Money-1605594364026","title":"金额","type":"price","value":"2500"}]]},{"id":"item-1494249126248","title":"备注","type":"textarea","value":""}] ) )
2021-01-07