在 Controller 中调用Lib
App::import('Lib','MyPrivacy');
$appId = Configure::read('pro.weixinpay.appId');
MyPrivacy::cancelUserPrivacy($appId,$openId);
若Lib在子文件夹中:
App::import('Lib/sub','MyPrivacy');
App::uses('Http', 'Lib');
/**
* 授权协议和隐私条款接口
*/
class MyPrivacy {
const baseUrl = 'http://myapi.com';
public static $queryData;
// 签名规则:签名 = appid拼接time拼接openid 后对其 sha1加密
protected static function _buildQueryData($appid,$openid){
$timeNow = time();
$Sign = '具体签名算法';
self::$queryData = [
"appid"=>$appid,
"openid"=>$openid,
"time"=>$timeNow,//当前时间戳
"sign"=>$Sign
];
}
//取消用户协议上报接口
public static function cancelUserPrivacy($appid,$openid) {
ULog::w(ULOG_INFO, __CLASS__.' ' . __FUNCTION__ . ' 0 params '.json_encode(func_get_args()));
self::_buildQueryData($appid,$openid);
return self::_makeQuery("/privacy/cancelUserPrivacy");
}
protected static function _makeQuery($apiName){
$url_data = self::baseUrl.$apiName;
$r = Http::postJson($url_data, self::$queryData);
if(200==$r['code']) {
return true;
}
return false;
}
网友评论