函数手册

函数手册

sendCustomMessage( )发送客服消息

文档教程geeson 发表了文章 • 0 个评论 • 1310 次浏览 • 2017-10-12 12:45 • 来自相关话题

/**
* @RhaPHP.com geeson
* 发送客服消息
* @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}}
* @return boolean|array
*/
function sendCustomMessage($data = [])
{
$wxObj = getWechatActiveObj();
$result = $wxObj->sendCustomMessage($data);
if (empty($result)) {
if ($wxObj->errCode == '45015') {
return ['errcode' => -1, 'errmsg' => '发送失败:此用户48小时内没有与公众号有过互动'];
}
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];

}
if (!isset($result['errcode']) && $result['errcode'] != '0') {
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];
} else {
return $result;
}
} 查看全部
/**
* @RhaPHP.com geeson
* 发送客服消息
* @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}}
* @return boolean|array
*/
function sendCustomMessage($data = [])
{
$wxObj = getWechatActiveObj();
$result = $wxObj->sendCustomMessage($data);
if (empty($result)) {
if ($wxObj->errCode == '45015') {
return ['errcode' => -1, 'errmsg' => '发送失败:此用户48小时内没有与公众号有过互动'];
}
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];

}
if (!isset($result['errcode']) && $result['errcode'] != '0') {
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];
} else {
return $result;
}
}

qiniuUpload( )七牛上传函数

文档教程geeson 发表了文章 • 0 个评论 • 807 次浏览 • 2017-10-12 12:44 • 来自相关话题

/**
* @param string $mid 公众号标识
* @param string $file 上传文件物理路径
* @param string $key 保护七牛中的文件名
* @return array
*/
function qiniuUpload($mid='',$file='',$key=''){
if(!$mid){
return ['code'=>1,'msg'=>'公众号标识mid不能为空'];
}else{
$st=getSetting($mid,'cloud');
if(!isset($st['qiniu']) && empty($st['qiniu'])){
return ['code'=>1,'msg'=>'请先配置七牛云存储参数'];
}else{
\think\Loader::import('QiniuSdk.Qiniu.autoload', EXTEND_PATH, '.php');

$client =Qiniu\Qiniu::create(array(
'access_key' => $st['qiniu']['accessKey'],
'secret_key' => $st['qiniu']['secretKey'],
'bucket' => $st['qiniu']['bucke'],
'domain' => $st['qiniu']['domain']
));
$result=$client->uploadFile($file,$key);
$result=json_decode(json_encode($result),true);
if(isset($result['response']['code']) && $result['response']['code'] !='200'){
return ['code'=>1,'msg'=>$result['error']];
}else{
return $res = [
'code' => 0,
'data' => [
'src' => $result['data']['url']
]
];
}
}
}

} 查看全部
/**
* @param string $mid 公众号标识
* @param string $file 上传文件物理路径
* @param string $key 保护七牛中的文件名
* @return array
*/
function qiniuUpload($mid='',$file='',$key=''){
if(!$mid){
return ['code'=>1,'msg'=>'公众号标识mid不能为空'];
}else{
$st=getSetting($mid,'cloud');
if(!isset($st['qiniu']) && empty($st['qiniu'])){
return ['code'=>1,'msg'=>'请先配置七牛云存储参数'];
}else{
\think\Loader::import('QiniuSdk.Qiniu.autoload', EXTEND_PATH, '.php');

$client =Qiniu\Qiniu::create(array(
'access_key' => $st['qiniu']['accessKey'],
'secret_key' => $st['qiniu']['secretKey'],
'bucket' => $st['qiniu']['bucke'],
'domain' => $st['qiniu']['domain']
));
$result=$client->uploadFile($file,$key);
$result=json_decode(json_encode($result),true);
if(isset($result['response']['code']) && $result['response']['code'] !='200'){
return ['code'=>1,'msg'=>$result['error']];
}else{
return $res = [
'code' => 0,
'data' => [
'src' => $result['data']['url']
]
];
}
}
}

}

singleSmsByTx( )短信普通单发(腾讯短信)

文档教程geeson 发表了文章 • 1 个评论 • 691 次浏览 • 2017-10-12 12:43 • 来自相关话题

/**
* 普通单发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
* @param int $type 短信类型,0 为普通短信,1 营销短信
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumber 不带国家码的手机号
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function singleSmsByTx($mid = '', $phoneNumber = '', $msg = '', $type = '0', $nationCode = '86', $extend = "", $ext = "")
{
\think\Loader::import('Qcloud.Sms.Loader', EXTEND_PATH, '.php');
if (!$conf = getSetting($mid, 'sms')) {
return false;//没有配置信息参数
}
$appid = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$appkey = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$singleSender = new \Qcloud\Sms\SmsSingleSender($appid, $appkey);
$result = $singleSender->send($type, $nationCode, $phoneNumber, $msg, "", "");
$rsp = json_decode($result);
return $rsp;

} 查看全部
/**
* 普通单发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
* @param int $type 短信类型,0 为普通短信,1 营销短信
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumber 不带国家码的手机号
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function singleSmsByTx($mid = '', $phoneNumber = '', $msg = '', $type = '0', $nationCode = '86', $extend = "", $ext = "")
{
\think\Loader::import('Qcloud.Sms.Loader', EXTEND_PATH, '.php');
if (!$conf = getSetting($mid, 'sms')) {
return false;//没有配置信息参数
}
$appid = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$appkey = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$singleSender = new \Qcloud\Sms\SmsSingleSender($appid, $appkey);
$result = $singleSender->send($type, $nationCode, $phoneNumber, $msg, "", "");
$rsp = json_decode($result);
return $rsp;

}

sendRedpack( )微信现金红包函数

文档教程geeson 发表了文章 • 0 个评论 • 841 次浏览 • 2017-10-12 12:41 • 来自相关话题

/**
* 现金红包
* 微信规定红包最小金额为1元
* 本函数输参数金额为元
* @param string $mid
* @param array $param
* @return array
*/
function sendRedpack($mid = '', $param = [], $addon = '')
{

if (setWxpayConfig($mid)) {
$url = "https://api.mch.weixin.qq.com/ ... 3B%3B
echo $order_number = time() . rand_string(18, 1);
$redpackObj = new Redpack();
$redpackObj->setParments("re_openid", isset($param['openid']) ? $param['openid'] : '');//openid
$redpackObj->setParments("mch_billno", $order_number);//订单号
$redpackObj->setParments("nick_name", isset($param['nick_name']) ? $param['nick_name'] : '有钱任性');//提供方名称|必填
$redpackObj->setParments("send_name", isset($param['send_name']) ? $param['send_name'] : '有钱的二狗子');//红包发送者名称|必填
$redpackObj->setParments("total_amount", isset($param['money']) ? $param['money'] * 100 : '');//付款金额,单位:元、元、元、|必填
$redpackObj->setParments("min_value", isset($param['min_value']) ? $param['min_value'] : '100');//最小红包金额,单位分
$redpackObj->setParments("max_value", isset($param['max_value']) ? $param['max_value'] : '100');//最大红包金额,单位分
$redpackObj->setParments("total_num", isset($param['total_num']) ? $param['total_num'] : '1');//红包収放总人数
$redpackObj->setParments("wishing", isset($param['wishing']) ? $param['wishing'] : '恭喜发财');//红包祝福诧
$redpackObj->setParments("client_ip", \think\Request::instance()->ip());//调用接口的机器 Ip 地址
$redpackObj->setParments("act_name", isset($param['act_name']) ? $param['act_name'] : '红包活动');//活动名称
$redpackObj->setParments("remark", isset($param['remark']) ? $param['remark'] : '红包活动');//备注信息
$redpackObj->setParments("nonce_str", getRandChar(32));//备注信息
$xml = $redpackObj->createRedpackXml();
$result = $redpackObj->xmlToArray($redpackObj->postXmlCurl($xml, $url, true));
$sslcert = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_cert.pem';
$sslkey = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_key.pem';
if (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') {
unlink($sslcert);
unlink($sslkey);
$model = new \app\common\model\Redpack();
$param['order_number'] = $order_number;
$param['mpid'] = $mid;
$param['create_time'] = time();
$param['addon'] = $addon;
$model->allowField(true)->save($param);
$param['errCode'] = 0;
$param['errMsg'] = '发放成功';
return $param;
} else {
unlink($sslcert);
unlink($sslkey);
return ['errCode' => -1, 'errMsg' => 'errMsg:' . $result['result_code'] . ':' . $result['return_msg']];
}
}else{
return ['errCode' => -1, 'errMsg' => 'errMsg:该公众号还没有配置支付相关的参数'];
}
} 查看全部
/**
* 现金红包
* 微信规定红包最小金额为1元
* 本函数输参数金额为元
* @param string $mid
* @param array $param
* @return array
*/
function sendRedpack($mid = '', $param = [], $addon = '')
{

if (setWxpayConfig($mid)) {
$url = "https://api.mch.weixin.qq.com/ ... 3B%3B
echo $order_number = time() . rand_string(18, 1);
$redpackObj = new Redpack();
$redpackObj->setParments("re_openid", isset($param['openid']) ? $param['openid'] : '');//openid
$redpackObj->setParments("mch_billno", $order_number);//订单号
$redpackObj->setParments("nick_name", isset($param['nick_name']) ? $param['nick_name'] : '有钱任性');//提供方名称|必填
$redpackObj->setParments("send_name", isset($param['send_name']) ? $param['send_name'] : '有钱的二狗子');//红包发送者名称|必填
$redpackObj->setParments("total_amount", isset($param['money']) ? $param['money'] * 100 : '');//付款金额,单位:元、元、元、|必填
$redpackObj->setParments("min_value", isset($param['min_value']) ? $param['min_value'] : '100');//最小红包金额,单位分
$redpackObj->setParments("max_value", isset($param['max_value']) ? $param['max_value'] : '100');//最大红包金额,单位分
$redpackObj->setParments("total_num", isset($param['total_num']) ? $param['total_num'] : '1');//红包収放总人数
$redpackObj->setParments("wishing", isset($param['wishing']) ? $param['wishing'] : '恭喜发财');//红包祝福诧
$redpackObj->setParments("client_ip", \think\Request::instance()->ip());//调用接口的机器 Ip 地址
$redpackObj->setParments("act_name", isset($param['act_name']) ? $param['act_name'] : '红包活动');//活动名称
$redpackObj->setParments("remark", isset($param['remark']) ? $param['remark'] : '红包活动');//备注信息
$redpackObj->setParments("nonce_str", getRandChar(32));//备注信息
$xml = $redpackObj->createRedpackXml();
$result = $redpackObj->xmlToArray($redpackObj->postXmlCurl($xml, $url, true));
$sslcert = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_cert.pem';
$sslkey = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_key.pem';
if (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') {
unlink($sslcert);
unlink($sslkey);
$model = new \app\common\model\Redpack();
$param['order_number'] = $order_number;
$param['mpid'] = $mid;
$param['create_time'] = time();
$param['addon'] = $addon;
$model->allowField(true)->save($param);
$param['errCode'] = 0;
$param['errMsg'] = '发放成功';
return $param;
} else {
unlink($sslcert);
unlink($sslkey);
return ['errCode' => -1, 'errMsg' => 'errMsg:' . $result['result_code'] . ':' . $result['return_msg']];
}
}else{
return ['errCode' => -1, 'errMsg' => 'errMsg:该公众号还没有配置支付相关的参数'];
}
}

queryOrder( )订单状态查询

文档教程geeson 发表了文章 • 0 个评论 • 619 次浏览 • 2017-10-12 12:40 • 来自相关话题

/**
* @param string $order_number 订单号
* @return array errCode ok: 成功 -1:失败
*/
function queryOrder($order_number = '')
{
$paymentModel = new \app\common\model\Payment();
if (!$payment = $paymentModel->getPaymentByFind(['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$input = new \WxPayOrderQuery();
$input->SetOut_trade_no($order_number);
$orderRes = \WxPayApi::orderQuery($input);
if (!empty($orderRes)) {
if (isset($orderRes['trade_state']) && $orderRes['trade_state'] == 'SUCCESS') {//已经支付
if ($payment['status'] == '0') {//订单状态未处理为成功
$model = new \app\common\model\MemberWealthRecord();
if ($model->addMoney($payment['member_id'], $payment['mpid'], $payment['money'], $payment['title'])) {
if (!$paymentModel->save(['status' => 1], ['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '改变订单状态失败'];
}
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
} else {
return ['errCode' => -1, 'errMsg' => '改变账户金额失败'];
}
} else {
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
}
} else {
return ['errCode' => -1, 'errMsg' => '未完成交易'];
}
} else {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
} 查看全部
/**
* @param string $order_number 订单号
* @return array errCode ok: 成功 -1:失败
*/
function queryOrder($order_number = '')
{
$paymentModel = new \app\common\model\Payment();
if (!$payment = $paymentModel->getPaymentByFind(['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$input = new \WxPayOrderQuery();
$input->SetOut_trade_no($order_number);
$orderRes = \WxPayApi::orderQuery($input);
if (!empty($orderRes)) {
if (isset($orderRes['trade_state']) && $orderRes['trade_state'] == 'SUCCESS') {//已经支付
if ($payment['status'] == '0') {//订单状态未处理为成功
$model = new \app\common\model\MemberWealthRecord();
if ($model->addMoney($payment['member_id'], $payment['mpid'], $payment['money'], $payment['title'])) {
if (!$paymentModel->save(['status' => 1], ['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '改变订单状态失败'];
}
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
} else {
return ['errCode' => -1, 'errMsg' => '改变账户金额失败'];
}
} else {
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
}
} else {
return ['errCode' => -1, 'errMsg' => '未完成交易'];
}
} else {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
}

wxPayByJsApi( )微信支付函数

文档教程geeson 发表了文章 • 0 个评论 • 738 次浏览 • 2017-10-12 12:38 • 来自相关话题

/**
* 微信支付函数
* @param $parment_id 定单id
* @param int $money
* @param string $openid
* @param string $mid 必须
* @param string $notifyUrl 通知地址
* @param string $body 商品描述
* @param string $goods_tag 订单优惠标记
* @param string $attach 附加数据
* @param string $trade_type 交易类型
* @return bool|json数据,可直接填入js函数作为参数
*/
function wxPayByJsApi($parment_id = '', $goods_tag = '', $trade_type = 'JSAPI')
{
$model = new \app\common\model\Payment();
if (!$payment = $model->getPaymentByFind(['payment_id' => $parment_id])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$tools = new \JsApiPay();
$input = new \WxPayUnifiedOrder();
$input->SetBody($payment['title']);
$input->SetAttach($payment['attach']);
$input->SetOut_trade_no($payment['order_number']);
$input->SetTotal_fee($payment['money'] * 100);
$input->SetTime_start(date("YmdHis"));//交易起始时间
$input->SetTime_expire(date("YmdHis", time() + 86400));//交易结束时间
$input->SetGoods_tag($goods_tag);
$input->SetNotify_url(\wxPayConfig::$NOTIFY_URL);
$input->SetTrade_type($trade_type);
$input->SetOpenid($payment['openid']);
$order = \WxPayApi::unifiedOrder($input);
if (isset($order['return_code'])) {
if ($order['return_code'] == 'SUCCESS') {
$jsApiParameters = $tools->GetJsApiParameters($order);
if ($jsApiParameters == false) {
return ['errCode' => -1, 'errMsg' => '获取API参数失败'];
} else {
return ['errCode' => 'ok', 'data' => $jsApiParameters];
}
} else {
return ['errCode' => -1, 'errMsg' => $order['return_code'] . $order['return_msg']];
}
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
} 查看全部
/**
* 微信支付函数
* @param $parment_id 定单id
* @param int $money
* @param string $openid
* @param string $mid 必须
* @param string $notifyUrl 通知地址
* @param string $body 商品描述
* @param string $goods_tag 订单优惠标记
* @param string $attach 附加数据
* @param string $trade_type 交易类型
* @return bool|json数据,可直接填入js函数作为参数
*/
function wxPayByJsApi($parment_id = '', $goods_tag = '', $trade_type = 'JSAPI')
{
$model = new \app\common\model\Payment();
if (!$payment = $model->getPaymentByFind(['payment_id' => $parment_id])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$tools = new \JsApiPay();
$input = new \WxPayUnifiedOrder();
$input->SetBody($payment['title']);
$input->SetAttach($payment['attach']);
$input->SetOut_trade_no($payment['order_number']);
$input->SetTotal_fee($payment['money'] * 100);
$input->SetTime_start(date("YmdHis"));//交易起始时间
$input->SetTime_expire(date("YmdHis", time() + 86400));//交易结束时间
$input->SetGoods_tag($goods_tag);
$input->SetNotify_url(\wxPayConfig::$NOTIFY_URL);
$input->SetTrade_type($trade_type);
$input->SetOpenid($payment['openid']);
$order = \WxPayApi::unifiedOrder($input);
if (isset($order['return_code'])) {
if ($order['return_code'] == 'SUCCESS') {
$jsApiParameters = $tools->GetJsApiParameters($order);
if ($jsApiParameters == false) {
return ['errCode' => -1, 'errMsg' => '获取API参数失败'];
} else {
return ['errCode' => 'ok', 'data' => $jsApiParameters];
}
} else {
return ['errCode' => -1, 'errMsg' => $order['return_code'] . $order['return_msg']];
}
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
}

getMember( )获取会员信息

文档教程geeson 发表了文章 • 0 个评论 • 930 次浏览 • 2017-10-12 12:36 • 来自相关话题

/**
* 获取会员(应用如需要使用会员登录,请使用本函数获取会员)
* 请区别 函数 getMemberInfo
* @return bool|mixed
*/
function getMember($member_id = '')
{
$friendModel = new \app\common\model\MpFriends();
if ($member_id) {
$member = $friendModel->getMemberInfo(['id' => $member_id]);
} else {
if (!$mid = input('mid')) {
exit('公众号标识mid不存在');
}
$c = cookie('member_' . $mid) ? cookie('member_' . $mid) : [];
$s = session('member_' . $mid) ? session('member_' . $mid) : [];
$member = array_merge($c, $s);
}
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['mpid' => $member['mpid']])->order('up_score ASC,up_money ASC,discount ASC')->select();
$group_id = '0';
$group_name = '';
if (!empty($group)) {
$model = new \app\common\model\MemberWealthRecord();
$score = $model->getMemberScoreBySum($member['id'], $member['mpid']);
$money = $model->getMemberMoneyBySum($member['id'], $member['mpid']);

foreach ($group as $key => $val) {
if ($val['up_type'] == '0') {
if ($score > $val['up_score'] || $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
} elseif ($val['up_type'] == '1') {
if ($score > $val['up_score'] && $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
}
}
$friendModel->updateMember(['id' => $member['id']], ['group_id' => $group_id]);
}
$member = $friendModel->getMemberInfo(['id' => $member['id']]);//可能COOKIE SESSION缓存原因 重新获取最新会员数据
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['gid' => $member['group_id']])->field('gid,group_name,discount')->find();
if (!empty($group)) {
$member['gid'] = $group['gid'];
$member['group_name'] = $group['group_name'];
$member['discount'] = $group['discount'];
} else {
$member['gid'] = '';
$member['group_name'] = '';
$member['discount'] = '';
}
return json_decode(json_encode($member), true);
} else {
//考虑没有认证号获取基本信息
return false;
}
} else {
return false;
}
} 查看全部
/**
* 获取会员(应用如需要使用会员登录,请使用本函数获取会员)
* 请区别 函数 getMemberInfo
* @return bool|mixed
*/
function getMember($member_id = '')
{
$friendModel = new \app\common\model\MpFriends();
if ($member_id) {
$member = $friendModel->getMemberInfo(['id' => $member_id]);
} else {
if (!$mid = input('mid')) {
exit('公众号标识mid不存在');
}
$c = cookie('member_' . $mid) ? cookie('member_' . $mid) : [];
$s = session('member_' . $mid) ? session('member_' . $mid) : [];
$member = array_merge($c, $s);
}
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['mpid' => $member['mpid']])->order('up_score ASC,up_money ASC,discount ASC')->select();
$group_id = '0';
$group_name = '';
if (!empty($group)) {
$model = new \app\common\model\MemberWealthRecord();
$score = $model->getMemberScoreBySum($member['id'], $member['mpid']);
$money = $model->getMemberMoneyBySum($member['id'], $member['mpid']);

foreach ($group as $key => $val) {
if ($val['up_type'] == '0') {
if ($score > $val['up_score'] || $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
} elseif ($val['up_type'] == '1') {
if ($score > $val['up_score'] && $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
}
}
$friendModel->updateMember(['id' => $member['id']], ['group_id' => $group_id]);
}
$member = $friendModel->getMemberInfo(['id' => $member['id']]);//可能COOKIE SESSION缓存原因 重新获取最新会员数据
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['gid' => $member['group_id']])->field('gid,group_name,discount')->find();
if (!empty($group)) {
$member['gid'] = $group['gid'];
$member['group_name'] = $group['group_name'];
$member['discount'] = $group['discount'];
} else {
$member['gid'] = '';
$member['group_name'] = '';
$member['discount'] = '';
}
return json_decode(json_encode($member), true);
} else {
//考虑没有认证号获取基本信息
return false;
}
} else {
return false;
}
}

getSetting( )获取公众功能配置信息,如微信支付,短信等等

文档教程geeson 发表了文章 • 0 个评论 • 284 次浏览 • 2017-10-12 12:35 • 来自相关话题

/**
* @param int $mid 公众号标识
* @param string $name 配置项名称
* @return array|false
*/
function getSetting($mid = 0, $name = '')
{
$model = new \app\common\model\Setting();
$result = $model->getSetting(['mpid' => $mid, 'name' => $name]);
return $result;
} 查看全部
/**
* @param int $mid 公众号标识
* @param string $name 配置项名称
* @return array|false
*/
function getSetting($mid = 0, $name = '')
{
$model = new \app\common\model\Setting();
$result = $model->getSetting(['mpid' => $mid, 'name' => $name]);
return $result;
}

createQrcode( )创建二维码(phpqrcode扩展)

文档教程geeson 发表了文章 • 0 个评论 • 643 次浏览 • 2017-10-12 12:33 • 来自相关话题

/**
*
* @param string $data
* @param bool $file
* @param string $level
* @param int $size
*/
function createQrcode($data = '', $file = false, $level = 'L', $size = 4)
{
\think\Loader::import('phpqrcode.phpqrcode', EXTEND_PATH, '.php');
header("Content-type: image/png");
Qrcode::png($data, $file, $level, $size);
} 查看全部
/**
*
* @param string $data
* @param bool $file
* @param string $level
* @param int $size
*/
function createQrcode($data = '', $file = false, $level = 'L', $size = 4)
{
\think\Loader::import('phpqrcode.phpqrcode', EXTEND_PATH, '.php');
header("Content-type: image/png");
Qrcode::png($data, $file, $level, $size);
}

getForeverMaterial( )获取永久素材列表(认证后的订阅号可用)

文档教程geeson 发表了文章 • 0 个评论 • 447 次浏览 • 2017-10-12 12:30 • 来自相关话题

/**
* 获取永久素材列表(认证后的订阅号可用)
* @param string $type 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
* @param int $offset 全部素材的偏移位置,0表示从第一个素材
* @param int $count 返回素材的数量
* @return boolean|array
* 返回数组格式:
* array(
* 'total_count'=>0, //该类型的素材的总数
* 'item_count'=>0, //本次调用获取的素材的数量
* 'item'=>array() //素材列表数组,内容定义请参考官方文档
* )
*/
function getForeverMaterial($type, $offset, $count)
{
$weObj = getWechatActiveObj();
return $weObj->getForeverList($type, $offset, $count);
} 查看全部
/**
* 获取永久素材列表(认证后的订阅号可用)
* @param string $type 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
* @param int $offset 全部素材的偏移位置,0表示从第一个素材
* @param int $count 返回素材的数量
* @return boolean|array
* 返回数组格式:
* array(
* 'total_count'=>0, //该类型的素材的总数
* 'item_count'=>0, //本次调用获取的素材的数量
* 'item'=>array() //素材列表数组,内容定义请参考官方文档
* )
*/
function getForeverMaterial($type, $offset, $count)
{
$weObj = getWechatActiveObj();
return $weObj->getForeverList($type, $offset, $count);
}

getFriendInfoForApi( )通过 openid请求 API获取粉丝信息

文档教程geeson 发表了文章 • 0 个评论 • 641 次浏览 • 2017-10-12 12:29 • 来自相关话题

/**
* 获取粉丝信息(通过 OPENID 获取)(认证后的订阅号可用)
* @param $openid srting
* return array
*/
function getFriendInfoForApi($openid = '')
{
$openid || $openid = session('openid');
$Obj = getWechatObj();
return $Obj->getUserInfo($openid);
} 查看全部
/**
* 获取粉丝信息(通过 OPENID 获取)(认证后的订阅号可用)
* @param $openid srting
* return array
*/
function getFriendInfoForApi($openid = '')
{
$openid || $openid = session('openid');
$Obj = getWechatObj();
return $Obj->getUserInfo($openid);
}

getMemberInfo( )通过openid获取会员信息

文档教程geeson 发表了文章 • 2 个评论 • 684 次浏览 • 2017-10-12 12:28 • 来自相关话题

/**
* @param string $openid
* @return array|false|PDOStatement|string|\think\Model
*/
function getMemberInfo($openid = '', $field = [])
{
if ($openid = getOrSetOpenid($openid)) {
$user = \think\Db::name('mp_friends')->where(['openid' => $openid])->find();
if (!$field) {
return $user;
} else {
$fields = [];
foreach ($field as $key => $val) {
$fields[$val] = $user[$val];
}
return $fields;
}

}
} 查看全部
/**
* @param string $openid
* @return array|false|PDOStatement|string|\think\Model
*/
function getMemberInfo($openid = '', $field = [])
{
if ($openid = getOrSetOpenid($openid)) {
$user = \think\Db::name('mp_friends')->where(['openid' => $openid])->find();
if (!$field) {
return $user;
} else {
$fields = [];
foreach ($field as $key => $val) {
$fields[$val] = $user[$val];
}
return $fields;
}

}
}

getOrSetOpenid( )设置或者获取openid

文档教程geeson 发表了文章 • 0 个评论 • 518 次浏览 • 2017-10-12 12:25 • 来自相关话题

/*
* 设置、获取 openid
*/

function getOrSetOpenid($openid = '')
{
if ($openid != '') {
session('openid', $openid);
return $openid;
} else {
$openid = session('openid');
if ($openid) {
return $openid;
} else {
return null;
}
}

} 查看全部
/*
* 设置、获取 openid
*/

function getOrSetOpenid($openid = '')
{
if ($openid != '') {
session('openid', $openid);
return $openid;
} else {
$openid = session('openid');
if ($openid) {
return $openid;
} else {
return null;
}
}

}

addonUrl( )应用URL生成【常用】

文档教程geeson 发表了文章 • 0 个评论 • 562 次浏览 • 2017-10-12 12:24 • 来自相关话题

/**
* 扩展应用 URL 生成
* @author geeson myrhzq@qq.com
* @param $url string 应用url/应用名称/控制器/方法
* @param $arr array 参数
*/
function addonUrl($url = '', $vars = '', $suffix = true, $domain = false)
{
if (!empty($addonRule = session('addonRule')) || $url != '') {
$addonName = isset($addonRule['addon']) ? $addonRule['addon'] : '';
$addonController = isset($addonRule['col']) ? $addonRule['col'] : '';
$addonAction = isset($addonRule['act']) ? $addonRule['act'] : '';
$node = '';
if ($url == '') {
$node = $addonName . DS . $addonController . DS . $addonAction;
} else {
$nodeArr = array_values(array_filter(explode('/', $url)));
switch (count($nodeArr)) {
case 1:
$node = $addonName . DS . $addonController . DS . $nodeArr[0];
break;
case 2:
$node = $addonName . DS . $nodeArr[0] . DS . $nodeArr[1];
break;
case 3:
$node = $node = $nodeArr[0] . DS . $nodeArr[1] . DS . $nodeArr[2];
break;
}
}
if (!empty($mid = input('mid'))) {
if (is_array($vars)) {
$vars = array_merge($vars, ['mid' => $mid]);
} elseif ($vars != '' && !is_array($vars)) {
$vars = $vars . '&' . 'mid=' . $mid;
} else {
$vars = ['mid' => $mid];
}
}
$url = \think\Url::build(ADDON_ROUTE . $node, $vars, $suffix, $domain);
return $url = str_replace('.' . config('template.view_suffix'), '', $url);

}
} 查看全部
/**
* 扩展应用 URL 生成
* @author geeson myrhzq@qq.com
* @param $url string 应用url/应用名称/控制器/方法
* @param $arr array 参数
*/
function addonUrl($url = '', $vars = '', $suffix = true, $domain = false)
{
if (!empty($addonRule = session('addonRule')) || $url != '') {
$addonName = isset($addonRule['addon']) ? $addonRule['addon'] : '';
$addonController = isset($addonRule['col']) ? $addonRule['col'] : '';
$addonAction = isset($addonRule['act']) ? $addonRule['act'] : '';
$node = '';
if ($url == '') {
$node = $addonName . DS . $addonController . DS . $addonAction;
} else {
$nodeArr = array_values(array_filter(explode('/', $url)));
switch (count($nodeArr)) {
case 1:
$node = $addonName . DS . $addonController . DS . $nodeArr[0];
break;
case 2:
$node = $addonName . DS . $nodeArr[0] . DS . $nodeArr[1];
break;
case 3:
$node = $node = $nodeArr[0] . DS . $nodeArr[1] . DS . $nodeArr[2];
break;
}
}
if (!empty($mid = input('mid'))) {
if (is_array($vars)) {
$vars = array_merge($vars, ['mid' => $mid]);
} elseif ($vars != '' && !is_array($vars)) {
$vars = $vars . '&' . 'mid=' . $mid;
} else {
$vars = ['mid' => $mid];
}
}
$url = \think\Url::build(ADDON_ROUTE . $node, $vars, $suffix, $domain);
return $url = str_replace('.' . config('template.view_suffix'), '', $url);

}
}

getAddonLogo( )获取应用LOGO

文档教程geeson 发表了文章 • 0 个评论 • 443 次浏览 • 2017-10-12 12:22 • 来自相关话题

/**
* @param string $name 应用标识
* @param $logoName
*/

function getAddonLogo($name = '')
{
if ($name == '') {
return false;
}
$model = new \app\common\model\Addons();
$info = $model->getAddonByFile($name);
$loginFile= ROOT_PATH. '/addons/' . $name . '/' . $info['logo'];
if(is_file($loginFile)){
if($fp = fopen($loginFile,"rb", 0))
{
$gambar = fread($fp,filesize($loginFile));
fclose($fp);
$base64 = chunk_split(base64_encode($gambar));
return $encode = 'data:image/jpg/png/gif;base64,' . $base64 ;
}
}
} 查看全部
/**
* @param string $name 应用标识
* @param $logoName
*/

function getAddonLogo($name = '')
{
if ($name == '') {
return false;
}
$model = new \app\common\model\Addons();
$info = $model->getAddonByFile($name);
$loginFile= ROOT_PATH. '/addons/' . $name . '/' . $info['logo'];
if(is_file($loginFile)){
if($fp = fopen($loginFile,"rb", 0))
{
$gambar = fread($fp,filesize($loginFile));
fclose($fp);
$base64 = chunk_split(base64_encode($gambar));
return $encode = 'data:image/jpg/png/gif;base64,' . $base64 ;
}
}
}

getAddonInfo( )获取应用配置信息

文档教程geeson 发表了文章 • 0 个评论 • 453 次浏览 • 2017-10-12 12:21 • 来自相关话题

/**
* 获取应用配置信息
* @author geeson myrhzq@qq.com
* $param $addonName string // 当前应用插件名称
* @param string mid 当前公众号标识ID
* @return array|bool|mixed
*/
function getAddonInfo($addonName = '', $mid = '')
{
if ($addonName == '' || $mid == '') {
$addonName = session('addonName');
$mid = session('mid')?session('mid'):input('mid');
}
if ($addonName == '' || $mid == '') {
exit('参数不完整:应用名称或者公众号标识不存在');
}
$addon = \think\Db::name('addons')->where(['addon' => $addonName])->find();
$addonInfo = \think\Db::name('addon_info')->where(['addon' => $addonName, 'mpid' => input('mid')])->find();
$addon['path'] = ADDON_PATH . $addonName . '/';
$addon['mp_config'] = json_decode($addonInfo['infos'], true);
$addon['common_config'] = json_decode($addon['config'], true);
unset($addon['config']);
return $addon;

}获取当前的应用一般不需要传参 查看全部
/**
* 获取应用配置信息
* @author geeson myrhzq@qq.com
* $param $addonName string // 当前应用插件名称
* @param string mid 当前公众号标识ID
* @return array|bool|mixed
*/
function getAddonInfo($addonName = '', $mid = '')
{
if ($addonName == '' || $mid == '') {
$addonName = session('addonName');
$mid = session('mid')?session('mid'):input('mid');
}
if ($addonName == '' || $mid == '') {
exit('参数不完整:应用名称或者公众号标识不存在');
}
$addon = \think\Db::name('addons')->where(['addon' => $addonName])->find();
$addonInfo = \think\Db::name('addon_info')->where(['addon' => $addonName, 'mpid' => input('mid')])->find();
$addon['path'] = ADDON_PATH . $addonName . '/';
$addon['mp_config'] = json_decode($addonInfo['infos'], true);
$addon['common_config'] = json_decode($addon['config'], true);
unset($addon['config']);
return $addon;

}
获取当前的应用一般不需要传参

getMpInfo( )获取公众号配置信息

文档教程geeson 发表了文章 • 0 个评论 • 534 次浏览 • 2017-10-12 12:19 • 来自相关话题

/**
* 获取公众号配置信息
* @param $mid number
*/

function getMpInfo($mid = '')
{
$mid ? $mid : $mid = input('mid');
$mpInfo = 'mpInfo_' . $mid;
if ($mid) {
$mp = \think\Db::name('mp')->where(['id' => $mid])->find();
if (!empty($mp)) {
return $mp;
} else {
abort(500, lang('没有找到相应的公众号信息'));
}

} else {
abort(500, lang('没有找到相应的公众号信息'));
}

} 查看全部
/**
* 获取公众号配置信息
* @param $mid number
*/

function getMpInfo($mid = '')
{
$mid ? $mid : $mid = input('mid');
$mpInfo = 'mpInfo_' . $mid;
if ($mid) {
$mp = \think\Db::name('mp')->where(['id' => $mid])->find();
if (!empty($mp)) {
return $mp;
} else {
abort(500, lang('没有找到相应的公众号信息'));
}

} else {
abort(500, lang('没有找到相应的公众号信息'));
}

}

getQrshortUrl( )长链接转短链接接口

文档教程geeson 发表了文章 • 0 个评论 • 416 次浏览 • 2017-10-12 12:17 • 来自相关话题

/**
* 长链接转短链接接口
* @param string $long_url 传入要转换的长url
* @return boolean|string url 成功则返回转换后的短url
*/
function getQrshortUrl($long_url)
{
$weObj = getWechatActiveObj();
return $weObj->getShortUrl($long_url);
} 查看全部
/**
* 长链接转短链接接口
* @param string $long_url 传入要转换的长url
* @return boolean|string url 成功则返回转换后的短url
*/
function getQrshortUrl($long_url)
{
$weObj = getWechatActiveObj();
return $weObj->getShortUrl($long_url);
}

getQrRUL( )获取二维码图片

文档教程geeson 发表了文章 • 0 个评论 • 583 次浏览 • 2017-10-12 12:16 • 来自相关话题

/**
* 获取二维码图片
* @param string $ticket 传入由get_qrcode方法生成的ticket参数
* @return string url 返回http地址
*/

function getQrRUL($ticket)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRUrl($ticket);
return $result;


} 查看全部
/**
* 获取二维码图片
* @param string $ticket 传入由get_qrcode方法生成的ticket参数
* @return string url 返回http地址
*/

function getQrRUL($ticket)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRUrl($ticket);
return $result;


}

get_qrcode( )创建二维码ticket

文档教程geeson 发表了文章 • 0 个评论 • 571 次浏览 • 2017-10-12 12:15 • 来自相关话题

/**
* 创建二维码ticket
* @param int|string $scene_id 自定义追踪id,临时二维码只能用数值型
* @param int $type 0:临时二维码;1:永久二维码(此时expire参数无效);2:永久二维码(此时expire参数无效)
* @param int $expire 临时二维码有效期,最大为604800秒

* @return array('ticket'=>'qrcode字串','expire_seconds'=>1800,'url'=>'二维码图片解析后的地址')
*/
function get_qrcode($scene_id, $type = 0, $expire = 1800)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRCode($scene_id, $type, $expire);
if (!$result) {
$return['errcode'] = 1001;
$return['errmsg'] = $weObj->errMsg;
// abort(500, lang('ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']));
ajaxMsg(0, 'ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']);
}
return $result;
} 查看全部
/**
* 创建二维码ticket
* @param int|string $scene_id 自定义追踪id,临时二维码只能用数值型
* @param int $type 0:临时二维码;1:永久二维码(此时expire参数无效);2:永久二维码(此时expire参数无效)
* @param int $expire 临时二维码有效期,最大为604800秒

* @return array('ticket'=>'qrcode字串','expire_seconds'=>1800,'url'=>'二维码图片解析后的地址')
*/
function get_qrcode($scene_id, $type = 0, $expire = 1800)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRCode($scene_id, $type, $expire);
if (!$result) {
$return['errcode'] = 1001;
$return['errmsg'] = $weObj->errMsg;
// abort(500, lang('ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']));
ajaxMsg(0, 'ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']);
}
return $result;
}

sendGroupMassMessage( ) 高级群发消息

文档教程geeson 发表了文章 • 0 个评论 • 512 次浏览 • 2017-10-12 12:14 • 来自相关话题

/**
* 高级群发消息, 根据群组id群发图文消息(认证后的订阅号可用)
* 注意:视频需要在调用uploadMedia()方法后,再使用 uploadMpVideo() 方法生成,
* 然后获得的 mediaid 才能用于群发,且消息类型为 mpvideo 类型。
* @param array $data 消息结构
* {
* "filter"=>array(
* "is_to_all"=>False, //是否群发给所有用户.True不用分组id,False需填写分组id
* "group_id"=>"2" //群发的分组id
* ),
* "msgtype"=>"mpvideo",
* // 在下面5种类型中选择对应的参数内容
* // mpnews | voice | image | mpvideo => array( "media_id"=>"MediaId")
* // text => array ( "content" => "hello")
* }
* @return boolean|array
*/
function sendGroupMassMessage($data)
{
$weObj = getWechatActiveObj();
$result = $weObj->sendGroupMassMessage($data);
if ($result) {
return $result;
} else {
$return['errCode'] = $weObj->errCode;
$return['errMsg'] = $weObj->errMsg;
return $return;
}
} 查看全部
/**
* 高级群发消息, 根据群组id群发图文消息(认证后的订阅号可用)
* 注意:视频需要在调用uploadMedia()方法后,再使用 uploadMpVideo() 方法生成,
* 然后获得的 mediaid 才能用于群发,且消息类型为 mpvideo 类型。
* @param array $data 消息结构
* {
* "filter"=>array(
* "is_to_all"=>False, //是否群发给所有用户.True不用分组id,False需填写分组id
* "group_id"=>"2" //群发的分组id
* ),
* "msgtype"=>"mpvideo",
* // 在下面5种类型中选择对应的参数内容
* // mpnews | voice | image | mpvideo => array( "media_id"=>"MediaId")
* // text => array ( "content" => "hello")
* }
* @return boolean|array
*/
function sendGroupMassMessage($data)
{
$weObj = getWechatActiveObj();
$result = $weObj->sendGroupMassMessage($data);
if ($result) {
return $result;
} else {
$return['errCode'] = $weObj->errCode;
$return['errMsg'] = $weObj->errMsg;
return $return;
}
}

replyNews( )回复图文

文档教程geeson 发表了文章 • 0 个评论 • 664 次浏览 • 2017-10-12 12:12 • 来自相关话题

/**
* 回复图文
* @author geeson myrhzq@qq.com
* @param $news array
数组结构:
array(
"0"=>array(
'Title'=>'msg title',
'Description'=>'Description text',
'PicUrl'=>'http://www.domain.com/1.jpg',
'Url'=>'http://www.domain.com/1.html'
),
"1"=>....
)
*/
function replyNews($new = [])
{
if (is_array($new)) {
$weObj = getWechatObj();
return $weObj->news($new)->reply();
}

} 查看全部
/**
* 回复图文
* @author geeson myrhzq@qq.com
* @param $news array
数组结构:
array(
"0"=>array(
'Title'=>'msg title',
'Description'=>'Description text',
'PicUrl'=>'http://www.domain.com/1.jpg',
'Url'=>'http://www.domain.com/1.html'
),
"1"=>....
)
*/
function replyNews($new = [])
{
if (is_array($new)) {
$weObj = getWechatObj();
return $weObj->news($new)->reply();
}

}

replyVideo( )回复视频消息

文档教程geeson 发表了文章 • 0 个评论 • 387 次浏览 • 2017-10-12 12:09 • 来自相关话题

/*
* 回复视频消息
* @param $mediaid string
* @param $title string
* @param $description string
*/
function replyVideo($mediaid = '', $title = '', $description = '')
{
$weObj = getWechatObj();
return $weObj->video($mediaid, $title, $description)->reply();
} 查看全部
/*
* 回复视频消息
* @param $mediaid string
* @param $title string
* @param $description string
*/
function replyVideo($mediaid = '', $title = '', $description = '')
{
$weObj = getWechatObj();
return $weObj->video($mediaid, $title, $description)->reply();
}

replyVoice( )回复语音消息

文档教程geeson 发表了文章 • 0 个评论 • 389 次浏览 • 2017-10-12 12:08 • 来自相关话题

/**
* 回复语音消息
* @param string media_id
*
*/
function replyVoice($media_id = '')
{
$weObj = getWechatObj();
return $weObj->voice($media_id)->reply();
} 查看全部
/**
* 回复语音消息
* @param string media_id
*
*/
function replyVoice($media_id = '')
{
$weObj = getWechatObj();
return $weObj->voice($media_id)->reply();
}

replyMusic( )回复音乐

文档教程geeson 发表了文章 • 0 个评论 • 375 次浏览 • 2017-10-12 12:08 • 来自相关话题

/**
* 设置回复音乐
* @param string $title
* @param string $desc
* @param string $musicurl
* @param string $hgmusicurl
* @param string $thumbmediaid 音乐图片缩略图的媒体id,非必须
*/
function replyMusic($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')
{
$weObj = getWechatObj();
return $weObj->music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')->reply();

} 查看全部
/**
* 设置回复音乐
* @param string $title
* @param string $desc
* @param string $musicurl
* @param string $hgmusicurl
* @param string $thumbmediaid 音乐图片缩略图的媒体id,非必须
*/
function replyMusic($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')
{
$weObj = getWechatObj();
return $weObj->music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')->reply();

}

sendCustomMessage( )发送客服消息

文档教程geeson 发表了文章 • 0 个评论 • 1310 次浏览 • 2017-10-12 12:45 • 来自相关话题

/**
* @RhaPHP.com geeson
* 发送客服消息
* @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}}
* @return boolean|array
*/
function sendCustomMessage($data = [])
{
$wxObj = getWechatActiveObj();
$result = $wxObj->sendCustomMessage($data);
if (empty($result)) {
if ($wxObj->errCode == '45015') {
return ['errcode' => -1, 'errmsg' => '发送失败:此用户48小时内没有与公众号有过互动'];
}
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];

}
if (!isset($result['errcode']) && $result['errcode'] != '0') {
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];
} else {
return $result;
}
} 查看全部
/**
* @RhaPHP.com geeson
* 发送客服消息
* @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}}
* @return boolean|array
*/
function sendCustomMessage($data = [])
{
$wxObj = getWechatActiveObj();
$result = $wxObj->sendCustomMessage($data);
if (empty($result)) {
if ($wxObj->errCode == '45015') {
return ['errcode' => -1, 'errmsg' => '发送失败:此用户48小时内没有与公众号有过互动'];
}
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];

}
if (!isset($result['errcode']) && $result['errcode'] != '0') {
return ['errcode' => -1, 'errmsg' => ' errCode:' . $wxObj->errCode . ' errMsg:' . $wxObj->errMsg];
} else {
return $result;
}
}

qiniuUpload( )七牛上传函数

文档教程geeson 发表了文章 • 0 个评论 • 807 次浏览 • 2017-10-12 12:44 • 来自相关话题

/**
* @param string $mid 公众号标识
* @param string $file 上传文件物理路径
* @param string $key 保护七牛中的文件名
* @return array
*/
function qiniuUpload($mid='',$file='',$key=''){
if(!$mid){
return ['code'=>1,'msg'=>'公众号标识mid不能为空'];
}else{
$st=getSetting($mid,'cloud');
if(!isset($st['qiniu']) && empty($st['qiniu'])){
return ['code'=>1,'msg'=>'请先配置七牛云存储参数'];
}else{
\think\Loader::import('QiniuSdk.Qiniu.autoload', EXTEND_PATH, '.php');

$client =Qiniu\Qiniu::create(array(
'access_key' => $st['qiniu']['accessKey'],
'secret_key' => $st['qiniu']['secretKey'],
'bucket' => $st['qiniu']['bucke'],
'domain' => $st['qiniu']['domain']
));
$result=$client->uploadFile($file,$key);
$result=json_decode(json_encode($result),true);
if(isset($result['response']['code']) && $result['response']['code'] !='200'){
return ['code'=>1,'msg'=>$result['error']];
}else{
return $res = [
'code' => 0,
'data' => [
'src' => $result['data']['url']
]
];
}
}
}

} 查看全部
/**
* @param string $mid 公众号标识
* @param string $file 上传文件物理路径
* @param string $key 保护七牛中的文件名
* @return array
*/
function qiniuUpload($mid='',$file='',$key=''){
if(!$mid){
return ['code'=>1,'msg'=>'公众号标识mid不能为空'];
}else{
$st=getSetting($mid,'cloud');
if(!isset($st['qiniu']) && empty($st['qiniu'])){
return ['code'=>1,'msg'=>'请先配置七牛云存储参数'];
}else{
\think\Loader::import('QiniuSdk.Qiniu.autoload', EXTEND_PATH, '.php');

$client =Qiniu\Qiniu::create(array(
'access_key' => $st['qiniu']['accessKey'],
'secret_key' => $st['qiniu']['secretKey'],
'bucket' => $st['qiniu']['bucke'],
'domain' => $st['qiniu']['domain']
));
$result=$client->uploadFile($file,$key);
$result=json_decode(json_encode($result),true);
if(isset($result['response']['code']) && $result['response']['code'] !='200'){
return ['code'=>1,'msg'=>$result['error']];
}else{
return $res = [
'code' => 0,
'data' => [
'src' => $result['data']['url']
]
];
}
}
}

}

singleSmsByTx( )短信普通单发(腾讯短信)

文档教程geeson 发表了文章 • 1 个评论 • 691 次浏览 • 2017-10-12 12:43 • 来自相关话题

/**
* 普通单发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
* @param int $type 短信类型,0 为普通短信,1 营销短信
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumber 不带国家码的手机号
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function singleSmsByTx($mid = '', $phoneNumber = '', $msg = '', $type = '0', $nationCode = '86', $extend = "", $ext = "")
{
\think\Loader::import('Qcloud.Sms.Loader', EXTEND_PATH, '.php');
if (!$conf = getSetting($mid, 'sms')) {
return false;//没有配置信息参数
}
$appid = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$appkey = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$singleSender = new \Qcloud\Sms\SmsSingleSender($appid, $appkey);
$result = $singleSender->send($type, $nationCode, $phoneNumber, $msg, "", "");
$rsp = json_decode($result);
return $rsp;

} 查看全部
/**
* 普通单发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
* @param int $type 短信类型,0 为普通短信,1 营销短信
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumber 不带国家码的手机号
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function singleSmsByTx($mid = '', $phoneNumber = '', $msg = '', $type = '0', $nationCode = '86', $extend = "", $ext = "")
{
\think\Loader::import('Qcloud.Sms.Loader', EXTEND_PATH, '.php');
if (!$conf = getSetting($mid, 'sms')) {
return false;//没有配置信息参数
}
$appid = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$appkey = isset($conf['txsms']['appid']) ? $conf['txsms']['appid'] : '';
$singleSender = new \Qcloud\Sms\SmsSingleSender($appid, $appkey);
$result = $singleSender->send($type, $nationCode, $phoneNumber, $msg, "", "");
$rsp = json_decode($result);
return $rsp;

}

sendRedpack( )微信现金红包函数

文档教程geeson 发表了文章 • 0 个评论 • 841 次浏览 • 2017-10-12 12:41 • 来自相关话题

/**
* 现金红包
* 微信规定红包最小金额为1元
* 本函数输参数金额为元
* @param string $mid
* @param array $param
* @return array
*/
function sendRedpack($mid = '', $param = [], $addon = '')
{

if (setWxpayConfig($mid)) {
$url = "https://api.mch.weixin.qq.com/ ... 3B%3B
echo $order_number = time() . rand_string(18, 1);
$redpackObj = new Redpack();
$redpackObj->setParments("re_openid", isset($param['openid']) ? $param['openid'] : '');//openid
$redpackObj->setParments("mch_billno", $order_number);//订单号
$redpackObj->setParments("nick_name", isset($param['nick_name']) ? $param['nick_name'] : '有钱任性');//提供方名称|必填
$redpackObj->setParments("send_name", isset($param['send_name']) ? $param['send_name'] : '有钱的二狗子');//红包发送者名称|必填
$redpackObj->setParments("total_amount", isset($param['money']) ? $param['money'] * 100 : '');//付款金额,单位:元、元、元、|必填
$redpackObj->setParments("min_value", isset($param['min_value']) ? $param['min_value'] : '100');//最小红包金额,单位分
$redpackObj->setParments("max_value", isset($param['max_value']) ? $param['max_value'] : '100');//最大红包金额,单位分
$redpackObj->setParments("total_num", isset($param['total_num']) ? $param['total_num'] : '1');//红包収放总人数
$redpackObj->setParments("wishing", isset($param['wishing']) ? $param['wishing'] : '恭喜发财');//红包祝福诧
$redpackObj->setParments("client_ip", \think\Request::instance()->ip());//调用接口的机器 Ip 地址
$redpackObj->setParments("act_name", isset($param['act_name']) ? $param['act_name'] : '红包活动');//活动名称
$redpackObj->setParments("remark", isset($param['remark']) ? $param['remark'] : '红包活动');//备注信息
$redpackObj->setParments("nonce_str", getRandChar(32));//备注信息
$xml = $redpackObj->createRedpackXml();
$result = $redpackObj->xmlToArray($redpackObj->postXmlCurl($xml, $url, true));
$sslcert = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_cert.pem';
$sslkey = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_key.pem';
if (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') {
unlink($sslcert);
unlink($sslkey);
$model = new \app\common\model\Redpack();
$param['order_number'] = $order_number;
$param['mpid'] = $mid;
$param['create_time'] = time();
$param['addon'] = $addon;
$model->allowField(true)->save($param);
$param['errCode'] = 0;
$param['errMsg'] = '发放成功';
return $param;
} else {
unlink($sslcert);
unlink($sslkey);
return ['errCode' => -1, 'errMsg' => 'errMsg:' . $result['result_code'] . ':' . $result['return_msg']];
}
}else{
return ['errCode' => -1, 'errMsg' => 'errMsg:该公众号还没有配置支付相关的参数'];
}
} 查看全部
/**
* 现金红包
* 微信规定红包最小金额为1元
* 本函数输参数金额为元
* @param string $mid
* @param array $param
* @return array
*/
function sendRedpack($mid = '', $param = [], $addon = '')
{

if (setWxpayConfig($mid)) {
$url = "https://api.mch.weixin.qq.com/ ... 3B%3B
echo $order_number = time() . rand_string(18, 1);
$redpackObj = new Redpack();
$redpackObj->setParments("re_openid", isset($param['openid']) ? $param['openid'] : '');//openid
$redpackObj->setParments("mch_billno", $order_number);//订单号
$redpackObj->setParments("nick_name", isset($param['nick_name']) ? $param['nick_name'] : '有钱任性');//提供方名称|必填
$redpackObj->setParments("send_name", isset($param['send_name']) ? $param['send_name'] : '有钱的二狗子');//红包发送者名称|必填
$redpackObj->setParments("total_amount", isset($param['money']) ? $param['money'] * 100 : '');//付款金额,单位:元、元、元、|必填
$redpackObj->setParments("min_value", isset($param['min_value']) ? $param['min_value'] : '100');//最小红包金额,单位分
$redpackObj->setParments("max_value", isset($param['max_value']) ? $param['max_value'] : '100');//最大红包金额,单位分
$redpackObj->setParments("total_num", isset($param['total_num']) ? $param['total_num'] : '1');//红包収放总人数
$redpackObj->setParments("wishing", isset($param['wishing']) ? $param['wishing'] : '恭喜发财');//红包祝福诧
$redpackObj->setParments("client_ip", \think\Request::instance()->ip());//调用接口的机器 Ip 地址
$redpackObj->setParments("act_name", isset($param['act_name']) ? $param['act_name'] : '红包活动');//活动名称
$redpackObj->setParments("remark", isset($param['remark']) ? $param['remark'] : '红包活动');//备注信息
$redpackObj->setParments("nonce_str", getRandChar(32));//备注信息
$xml = $redpackObj->createRedpackXml();
$result = $redpackObj->xmlToArray($redpackObj->postXmlCurl($xml, $url, true));
$sslcert = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_cert.pem';
$sslkey = ROOT_PATH . 'data/' . $mid . '_' . '_apiclient_key.pem';
if (isset($result['result_code']) && $result['result_code'] == 'SUCCESS') {
unlink($sslcert);
unlink($sslkey);
$model = new \app\common\model\Redpack();
$param['order_number'] = $order_number;
$param['mpid'] = $mid;
$param['create_time'] = time();
$param['addon'] = $addon;
$model->allowField(true)->save($param);
$param['errCode'] = 0;
$param['errMsg'] = '发放成功';
return $param;
} else {
unlink($sslcert);
unlink($sslkey);
return ['errCode' => -1, 'errMsg' => 'errMsg:' . $result['result_code'] . ':' . $result['return_msg']];
}
}else{
return ['errCode' => -1, 'errMsg' => 'errMsg:该公众号还没有配置支付相关的参数'];
}
}

queryOrder( )订单状态查询

文档教程geeson 发表了文章 • 0 个评论 • 619 次浏览 • 2017-10-12 12:40 • 来自相关话题

/**
* @param string $order_number 订单号
* @return array errCode ok: 成功 -1:失败
*/
function queryOrder($order_number = '')
{
$paymentModel = new \app\common\model\Payment();
if (!$payment = $paymentModel->getPaymentByFind(['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$input = new \WxPayOrderQuery();
$input->SetOut_trade_no($order_number);
$orderRes = \WxPayApi::orderQuery($input);
if (!empty($orderRes)) {
if (isset($orderRes['trade_state']) && $orderRes['trade_state'] == 'SUCCESS') {//已经支付
if ($payment['status'] == '0') {//订单状态未处理为成功
$model = new \app\common\model\MemberWealthRecord();
if ($model->addMoney($payment['member_id'], $payment['mpid'], $payment['money'], $payment['title'])) {
if (!$paymentModel->save(['status' => 1], ['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '改变订单状态失败'];
}
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
} else {
return ['errCode' => -1, 'errMsg' => '改变账户金额失败'];
}
} else {
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
}
} else {
return ['errCode' => -1, 'errMsg' => '未完成交易'];
}
} else {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
} 查看全部
/**
* @param string $order_number 订单号
* @return array errCode ok: 成功 -1:失败
*/
function queryOrder($order_number = '')
{
$paymentModel = new \app\common\model\Payment();
if (!$payment = $paymentModel->getPaymentByFind(['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$input = new \WxPayOrderQuery();
$input->SetOut_trade_no($order_number);
$orderRes = \WxPayApi::orderQuery($input);
if (!empty($orderRes)) {
if (isset($orderRes['trade_state']) && $orderRes['trade_state'] == 'SUCCESS') {//已经支付
if ($payment['status'] == '0') {//订单状态未处理为成功
$model = new \app\common\model\MemberWealthRecord();
if ($model->addMoney($payment['member_id'], $payment['mpid'], $payment['money'], $payment['title'])) {
if (!$paymentModel->save(['status' => 1], ['order_number' => $order_number])) {
return ['errCode' => -1, 'errMsg' => '改变订单状态失败'];
}
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
} else {
return ['errCode' => -1, 'errMsg' => '改变账户金额失败'];
}
} else {
return ['errCode' => 'ok', 'errMsg' => '交易完成'];
}
} else {
return ['errCode' => -1, 'errMsg' => '未完成交易'];
}
} else {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
}

wxPayByJsApi( )微信支付函数

文档教程geeson 发表了文章 • 0 个评论 • 738 次浏览 • 2017-10-12 12:38 • 来自相关话题

/**
* 微信支付函数
* @param $parment_id 定单id
* @param int $money
* @param string $openid
* @param string $mid 必须
* @param string $notifyUrl 通知地址
* @param string $body 商品描述
* @param string $goods_tag 订单优惠标记
* @param string $attach 附加数据
* @param string $trade_type 交易类型
* @return bool|json数据,可直接填入js函数作为参数
*/
function wxPayByJsApi($parment_id = '', $goods_tag = '', $trade_type = 'JSAPI')
{
$model = new \app\common\model\Payment();
if (!$payment = $model->getPaymentByFind(['payment_id' => $parment_id])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$tools = new \JsApiPay();
$input = new \WxPayUnifiedOrder();
$input->SetBody($payment['title']);
$input->SetAttach($payment['attach']);
$input->SetOut_trade_no($payment['order_number']);
$input->SetTotal_fee($payment['money'] * 100);
$input->SetTime_start(date("YmdHis"));//交易起始时间
$input->SetTime_expire(date("YmdHis", time() + 86400));//交易结束时间
$input->SetGoods_tag($goods_tag);
$input->SetNotify_url(\wxPayConfig::$NOTIFY_URL);
$input->SetTrade_type($trade_type);
$input->SetOpenid($payment['openid']);
$order = \WxPayApi::unifiedOrder($input);
if (isset($order['return_code'])) {
if ($order['return_code'] == 'SUCCESS') {
$jsApiParameters = $tools->GetJsApiParameters($order);
if ($jsApiParameters == false) {
return ['errCode' => -1, 'errMsg' => '获取API参数失败'];
} else {
return ['errCode' => 'ok', 'data' => $jsApiParameters];
}
} else {
return ['errCode' => -1, 'errMsg' => $order['return_code'] . $order['return_msg']];
}
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
} 查看全部
/**
* 微信支付函数
* @param $parment_id 定单id
* @param int $money
* @param string $openid
* @param string $mid 必须
* @param string $notifyUrl 通知地址
* @param string $body 商品描述
* @param string $goods_tag 订单优惠标记
* @param string $attach 附加数据
* @param string $trade_type 交易类型
* @return bool|json数据,可直接填入js函数作为参数
*/
function wxPayByJsApi($parment_id = '', $goods_tag = '', $trade_type = 'JSAPI')
{
$model = new \app\common\model\Payment();
if (!$payment = $model->getPaymentByFind(['payment_id' => $parment_id])) {
return ['errCode' => -1, 'errMsg' => '订单不存在'];
}
if (setWxpayConfig($payment['mpid'])) {
$tools = new \JsApiPay();
$input = new \WxPayUnifiedOrder();
$input->SetBody($payment['title']);
$input->SetAttach($payment['attach']);
$input->SetOut_trade_no($payment['order_number']);
$input->SetTotal_fee($payment['money'] * 100);
$input->SetTime_start(date("YmdHis"));//交易起始时间
$input->SetTime_expire(date("YmdHis", time() + 86400));//交易结束时间
$input->SetGoods_tag($goods_tag);
$input->SetNotify_url(\wxPayConfig::$NOTIFY_URL);
$input->SetTrade_type($trade_type);
$input->SetOpenid($payment['openid']);
$order = \WxPayApi::unifiedOrder($input);
if (isset($order['return_code'])) {
if ($order['return_code'] == 'SUCCESS') {
$jsApiParameters = $tools->GetJsApiParameters($order);
if ($jsApiParameters == false) {
return ['errCode' => -1, 'errMsg' => '获取API参数失败'];
} else {
return ['errCode' => 'ok', 'data' => $jsApiParameters];
}
} else {
return ['errCode' => -1, 'errMsg' => $order['return_code'] . $order['return_msg']];
}
}
}
return ['errCode' => -1, 'errMsg' => '没有公众号配置信息'];
}

getMember( )获取会员信息

文档教程geeson 发表了文章 • 0 个评论 • 930 次浏览 • 2017-10-12 12:36 • 来自相关话题

/**
* 获取会员(应用如需要使用会员登录,请使用本函数获取会员)
* 请区别 函数 getMemberInfo
* @return bool|mixed
*/
function getMember($member_id = '')
{
$friendModel = new \app\common\model\MpFriends();
if ($member_id) {
$member = $friendModel->getMemberInfo(['id' => $member_id]);
} else {
if (!$mid = input('mid')) {
exit('公众号标识mid不存在');
}
$c = cookie('member_' . $mid) ? cookie('member_' . $mid) : [];
$s = session('member_' . $mid) ? session('member_' . $mid) : [];
$member = array_merge($c, $s);
}
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['mpid' => $member['mpid']])->order('up_score ASC,up_money ASC,discount ASC')->select();
$group_id = '0';
$group_name = '';
if (!empty($group)) {
$model = new \app\common\model\MemberWealthRecord();
$score = $model->getMemberScoreBySum($member['id'], $member['mpid']);
$money = $model->getMemberMoneyBySum($member['id'], $member['mpid']);

foreach ($group as $key => $val) {
if ($val['up_type'] == '0') {
if ($score > $val['up_score'] || $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
} elseif ($val['up_type'] == '1') {
if ($score > $val['up_score'] && $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
}
}
$friendModel->updateMember(['id' => $member['id']], ['group_id' => $group_id]);
}
$member = $friendModel->getMemberInfo(['id' => $member['id']]);//可能COOKIE SESSION缓存原因 重新获取最新会员数据
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['gid' => $member['group_id']])->field('gid,group_name,discount')->find();
if (!empty($group)) {
$member['gid'] = $group['gid'];
$member['group_name'] = $group['group_name'];
$member['discount'] = $group['discount'];
} else {
$member['gid'] = '';
$member['group_name'] = '';
$member['discount'] = '';
}
return json_decode(json_encode($member), true);
} else {
//考虑没有认证号获取基本信息
return false;
}
} else {
return false;
}
} 查看全部
/**
* 获取会员(应用如需要使用会员登录,请使用本函数获取会员)
* 请区别 函数 getMemberInfo
* @return bool|mixed
*/
function getMember($member_id = '')
{
$friendModel = new \app\common\model\MpFriends();
if ($member_id) {
$member = $friendModel->getMemberInfo(['id' => $member_id]);
} else {
if (!$mid = input('mid')) {
exit('公众号标识mid不存在');
}
$c = cookie('member_' . $mid) ? cookie('member_' . $mid) : [];
$s = session('member_' . $mid) ? session('member_' . $mid) : [];
$member = array_merge($c, $s);
}
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['mpid' => $member['mpid']])->order('up_score ASC,up_money ASC,discount ASC')->select();
$group_id = '0';
$group_name = '';
if (!empty($group)) {
$model = new \app\common\model\MemberWealthRecord();
$score = $model->getMemberScoreBySum($member['id'], $member['mpid']);
$money = $model->getMemberMoneyBySum($member['id'], $member['mpid']);

foreach ($group as $key => $val) {
if ($val['up_type'] == '0') {
if ($score > $val['up_score'] || $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
} elseif ($val['up_type'] == '1') {
if ($score > $val['up_score'] && $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
}
}
$friendModel->updateMember(['id' => $member['id']], ['group_id' => $group_id]);
}
$member = $friendModel->getMemberInfo(['id' => $member['id']]);//可能COOKIE SESSION缓存原因 重新获取最新会员数据
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['gid' => $member['group_id']])->field('gid,group_name,discount')->find();
if (!empty($group)) {
$member['gid'] = $group['gid'];
$member['group_name'] = $group['group_name'];
$member['discount'] = $group['discount'];
} else {
$member['gid'] = '';
$member['group_name'] = '';
$member['discount'] = '';
}
return json_decode(json_encode($member), true);
} else {
//考虑没有认证号获取基本信息
return false;
}
} else {
return false;
}
}

getSetting( )获取公众功能配置信息,如微信支付,短信等等

文档教程geeson 发表了文章 • 0 个评论 • 284 次浏览 • 2017-10-12 12:35 • 来自相关话题

/**
* @param int $mid 公众号标识
* @param string $name 配置项名称
* @return array|false
*/
function getSetting($mid = 0, $name = '')
{
$model = new \app\common\model\Setting();
$result = $model->getSetting(['mpid' => $mid, 'name' => $name]);
return $result;
} 查看全部
/**
* @param int $mid 公众号标识
* @param string $name 配置项名称
* @return array|false
*/
function getSetting($mid = 0, $name = '')
{
$model = new \app\common\model\Setting();
$result = $model->getSetting(['mpid' => $mid, 'name' => $name]);
return $result;
}

createQrcode( )创建二维码(phpqrcode扩展)

文档教程geeson 发表了文章 • 0 个评论 • 643 次浏览 • 2017-10-12 12:33 • 来自相关话题

/**
*
* @param string $data
* @param bool $file
* @param string $level
* @param int $size
*/
function createQrcode($data = '', $file = false, $level = 'L', $size = 4)
{
\think\Loader::import('phpqrcode.phpqrcode', EXTEND_PATH, '.php');
header("Content-type: image/png");
Qrcode::png($data, $file, $level, $size);
} 查看全部
/**
*
* @param string $data
* @param bool $file
* @param string $level
* @param int $size
*/
function createQrcode($data = '', $file = false, $level = 'L', $size = 4)
{
\think\Loader::import('phpqrcode.phpqrcode', EXTEND_PATH, '.php');
header("Content-type: image/png");
Qrcode::png($data, $file, $level, $size);
}

getForeverMaterial( )获取永久素材列表(认证后的订阅号可用)

文档教程geeson 发表了文章 • 0 个评论 • 447 次浏览 • 2017-10-12 12:30 • 来自相关话题

/**
* 获取永久素材列表(认证后的订阅号可用)
* @param string $type 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
* @param int $offset 全部素材的偏移位置,0表示从第一个素材
* @param int $count 返回素材的数量
* @return boolean|array
* 返回数组格式:
* array(
* 'total_count'=>0, //该类型的素材的总数
* 'item_count'=>0, //本次调用获取的素材的数量
* 'item'=>array() //素材列表数组,内容定义请参考官方文档
* )
*/
function getForeverMaterial($type, $offset, $count)
{
$weObj = getWechatActiveObj();
return $weObj->getForeverList($type, $offset, $count);
} 查看全部
/**
* 获取永久素材列表(认证后的订阅号可用)
* @param string $type 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
* @param int $offset 全部素材的偏移位置,0表示从第一个素材
* @param int $count 返回素材的数量
* @return boolean|array
* 返回数组格式:
* array(
* 'total_count'=>0, //该类型的素材的总数
* 'item_count'=>0, //本次调用获取的素材的数量
* 'item'=>array() //素材列表数组,内容定义请参考官方文档
* )
*/
function getForeverMaterial($type, $offset, $count)
{
$weObj = getWechatActiveObj();
return $weObj->getForeverList($type, $offset, $count);
}

getFriendInfoForApi( )通过 openid请求 API获取粉丝信息

文档教程geeson 发表了文章 • 0 个评论 • 641 次浏览 • 2017-10-12 12:29 • 来自相关话题

/**
* 获取粉丝信息(通过 OPENID 获取)(认证后的订阅号可用)
* @param $openid srting
* return array
*/
function getFriendInfoForApi($openid = '')
{
$openid || $openid = session('openid');
$Obj = getWechatObj();
return $Obj->getUserInfo($openid);
} 查看全部
/**
* 获取粉丝信息(通过 OPENID 获取)(认证后的订阅号可用)
* @param $openid srting
* return array
*/
function getFriendInfoForApi($openid = '')
{
$openid || $openid = session('openid');
$Obj = getWechatObj();
return $Obj->getUserInfo($openid);
}

getMemberInfo( )通过openid获取会员信息

文档教程geeson 发表了文章 • 2 个评论 • 684 次浏览 • 2017-10-12 12:28 • 来自相关话题

/**
* @param string $openid
* @return array|false|PDOStatement|string|\think\Model
*/
function getMemberInfo($openid = '', $field = [])
{
if ($openid = getOrSetOpenid($openid)) {
$user = \think\Db::name('mp_friends')->where(['openid' => $openid])->find();
if (!$field) {
return $user;
} else {
$fields = [];
foreach ($field as $key => $val) {
$fields[$val] = $user[$val];
}
return $fields;
}

}
} 查看全部
/**
* @param string $openid
* @return array|false|PDOStatement|string|\think\Model
*/
function getMemberInfo($openid = '', $field = [])
{
if ($openid = getOrSetOpenid($openid)) {
$user = \think\Db::name('mp_friends')->where(['openid' => $openid])->find();
if (!$field) {
return $user;
} else {
$fields = [];
foreach ($field as $key => $val) {
$fields[$val] = $user[$val];
}
return $fields;
}

}
}

getOrSetOpenid( )设置或者获取openid

文档教程geeson 发表了文章 • 0 个评论 • 518 次浏览 • 2017-10-12 12:25 • 来自相关话题

/*
* 设置、获取 openid
*/

function getOrSetOpenid($openid = '')
{
if ($openid != '') {
session('openid', $openid);
return $openid;
} else {
$openid = session('openid');
if ($openid) {
return $openid;
} else {
return null;
}
}

} 查看全部
/*
* 设置、获取 openid
*/

function getOrSetOpenid($openid = '')
{
if ($openid != '') {
session('openid', $openid);
return $openid;
} else {
$openid = session('openid');
if ($openid) {
return $openid;
} else {
return null;
}
}

}

addonUrl( )应用URL生成【常用】

文档教程geeson 发表了文章 • 0 个评论 • 562 次浏览 • 2017-10-12 12:24 • 来自相关话题

/**
* 扩展应用 URL 生成
* @author geeson myrhzq@qq.com
* @param $url string 应用url/应用名称/控制器/方法
* @param $arr array 参数
*/
function addonUrl($url = '', $vars = '', $suffix = true, $domain = false)
{
if (!empty($addonRule = session('addonRule')) || $url != '') {
$addonName = isset($addonRule['addon']) ? $addonRule['addon'] : '';
$addonController = isset($addonRule['col']) ? $addonRule['col'] : '';
$addonAction = isset($addonRule['act']) ? $addonRule['act'] : '';
$node = '';
if ($url == '') {
$node = $addonName . DS . $addonController . DS . $addonAction;
} else {
$nodeArr = array_values(array_filter(explode('/', $url)));
switch (count($nodeArr)) {
case 1:
$node = $addonName . DS . $addonController . DS . $nodeArr[0];
break;
case 2:
$node = $addonName . DS . $nodeArr[0] . DS . $nodeArr[1];
break;
case 3:
$node = $node = $nodeArr[0] . DS . $nodeArr[1] . DS . $nodeArr[2];
break;
}
}
if (!empty($mid = input('mid'))) {
if (is_array($vars)) {
$vars = array_merge($vars, ['mid' => $mid]);
} elseif ($vars != '' && !is_array($vars)) {
$vars = $vars . '&' . 'mid=' . $mid;
} else {
$vars = ['mid' => $mid];
}
}
$url = \think\Url::build(ADDON_ROUTE . $node, $vars, $suffix, $domain);
return $url = str_replace('.' . config('template.view_suffix'), '', $url);

}
} 查看全部
/**
* 扩展应用 URL 生成
* @author geeson myrhzq@qq.com
* @param $url string 应用url/应用名称/控制器/方法
* @param $arr array 参数
*/
function addonUrl($url = '', $vars = '', $suffix = true, $domain = false)
{
if (!empty($addonRule = session('addonRule')) || $url != '') {
$addonName = isset($addonRule['addon']) ? $addonRule['addon'] : '';
$addonController = isset($addonRule['col']) ? $addonRule['col'] : '';
$addonAction = isset($addonRule['act']) ? $addonRule['act'] : '';
$node = '';
if ($url == '') {
$node = $addonName . DS . $addonController . DS . $addonAction;
} else {
$nodeArr = array_values(array_filter(explode('/', $url)));
switch (count($nodeArr)) {
case 1:
$node = $addonName . DS . $addonController . DS . $nodeArr[0];
break;
case 2:
$node = $addonName . DS . $nodeArr[0] . DS . $nodeArr[1];
break;
case 3:
$node = $node = $nodeArr[0] . DS . $nodeArr[1] . DS . $nodeArr[2];
break;
}
}
if (!empty($mid = input('mid'))) {
if (is_array($vars)) {
$vars = array_merge($vars, ['mid' => $mid]);
} elseif ($vars != '' && !is_array($vars)) {
$vars = $vars . '&' . 'mid=' . $mid;
} else {
$vars = ['mid' => $mid];
}
}
$url = \think\Url::build(ADDON_ROUTE . $node, $vars, $suffix, $domain);
return $url = str_replace('.' . config('template.view_suffix'), '', $url);

}
}

getAddonLogo( )获取应用LOGO

文档教程geeson 发表了文章 • 0 个评论 • 443 次浏览 • 2017-10-12 12:22 • 来自相关话题

/**
* @param string $name 应用标识
* @param $logoName
*/

function getAddonLogo($name = '')
{
if ($name == '') {
return false;
}
$model = new \app\common\model\Addons();
$info = $model->getAddonByFile($name);
$loginFile= ROOT_PATH. '/addons/' . $name . '/' . $info['logo'];
if(is_file($loginFile)){
if($fp = fopen($loginFile,"rb", 0))
{
$gambar = fread($fp,filesize($loginFile));
fclose($fp);
$base64 = chunk_split(base64_encode($gambar));
return $encode = 'data:image/jpg/png/gif;base64,' . $base64 ;
}
}
} 查看全部
/**
* @param string $name 应用标识
* @param $logoName
*/

function getAddonLogo($name = '')
{
if ($name == '') {
return false;
}
$model = new \app\common\model\Addons();
$info = $model->getAddonByFile($name);
$loginFile= ROOT_PATH. '/addons/' . $name . '/' . $info['logo'];
if(is_file($loginFile)){
if($fp = fopen($loginFile,"rb", 0))
{
$gambar = fread($fp,filesize($loginFile));
fclose($fp);
$base64 = chunk_split(base64_encode($gambar));
return $encode = 'data:image/jpg/png/gif;base64,' . $base64 ;
}
}
}

getAddonInfo( )获取应用配置信息

文档教程geeson 发表了文章 • 0 个评论 • 453 次浏览 • 2017-10-12 12:21 • 来自相关话题

/**
* 获取应用配置信息
* @author geeson myrhzq@qq.com
* $param $addonName string // 当前应用插件名称
* @param string mid 当前公众号标识ID
* @return array|bool|mixed
*/
function getAddonInfo($addonName = '', $mid = '')
{
if ($addonName == '' || $mid == '') {
$addonName = session('addonName');
$mid = session('mid')?session('mid'):input('mid');
}
if ($addonName == '' || $mid == '') {
exit('参数不完整:应用名称或者公众号标识不存在');
}
$addon = \think\Db::name('addons')->where(['addon' => $addonName])->find();
$addonInfo = \think\Db::name('addon_info')->where(['addon' => $addonName, 'mpid' => input('mid')])->find();
$addon['path'] = ADDON_PATH . $addonName . '/';
$addon['mp_config'] = json_decode($addonInfo['infos'], true);
$addon['common_config'] = json_decode($addon['config'], true);
unset($addon['config']);
return $addon;

}获取当前的应用一般不需要传参 查看全部
/**
* 获取应用配置信息
* @author geeson myrhzq@qq.com
* $param $addonName string // 当前应用插件名称
* @param string mid 当前公众号标识ID
* @return array|bool|mixed
*/
function getAddonInfo($addonName = '', $mid = '')
{
if ($addonName == '' || $mid == '') {
$addonName = session('addonName');
$mid = session('mid')?session('mid'):input('mid');
}
if ($addonName == '' || $mid == '') {
exit('参数不完整:应用名称或者公众号标识不存在');
}
$addon = \think\Db::name('addons')->where(['addon' => $addonName])->find();
$addonInfo = \think\Db::name('addon_info')->where(['addon' => $addonName, 'mpid' => input('mid')])->find();
$addon['path'] = ADDON_PATH . $addonName . '/';
$addon['mp_config'] = json_decode($addonInfo['infos'], true);
$addon['common_config'] = json_decode($addon['config'], true);
unset($addon['config']);
return $addon;

}
获取当前的应用一般不需要传参

getMpInfo( )获取公众号配置信息

文档教程geeson 发表了文章 • 0 个评论 • 534 次浏览 • 2017-10-12 12:19 • 来自相关话题

/**
* 获取公众号配置信息
* @param $mid number
*/

function getMpInfo($mid = '')
{
$mid ? $mid : $mid = input('mid');
$mpInfo = 'mpInfo_' . $mid;
if ($mid) {
$mp = \think\Db::name('mp')->where(['id' => $mid])->find();
if (!empty($mp)) {
return $mp;
} else {
abort(500, lang('没有找到相应的公众号信息'));
}

} else {
abort(500, lang('没有找到相应的公众号信息'));
}

} 查看全部
/**
* 获取公众号配置信息
* @param $mid number
*/

function getMpInfo($mid = '')
{
$mid ? $mid : $mid = input('mid');
$mpInfo = 'mpInfo_' . $mid;
if ($mid) {
$mp = \think\Db::name('mp')->where(['id' => $mid])->find();
if (!empty($mp)) {
return $mp;
} else {
abort(500, lang('没有找到相应的公众号信息'));
}

} else {
abort(500, lang('没有找到相应的公众号信息'));
}

}

getQrshortUrl( )长链接转短链接接口

文档教程geeson 发表了文章 • 0 个评论 • 416 次浏览 • 2017-10-12 12:17 • 来自相关话题

/**
* 长链接转短链接接口
* @param string $long_url 传入要转换的长url
* @return boolean|string url 成功则返回转换后的短url
*/
function getQrshortUrl($long_url)
{
$weObj = getWechatActiveObj();
return $weObj->getShortUrl($long_url);
} 查看全部
/**
* 长链接转短链接接口
* @param string $long_url 传入要转换的长url
* @return boolean|string url 成功则返回转换后的短url
*/
function getQrshortUrl($long_url)
{
$weObj = getWechatActiveObj();
return $weObj->getShortUrl($long_url);
}

getQrRUL( )获取二维码图片

文档教程geeson 发表了文章 • 0 个评论 • 583 次浏览 • 2017-10-12 12:16 • 来自相关话题

/**
* 获取二维码图片
* @param string $ticket 传入由get_qrcode方法生成的ticket参数
* @return string url 返回http地址
*/

function getQrRUL($ticket)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRUrl($ticket);
return $result;


} 查看全部
/**
* 获取二维码图片
* @param string $ticket 传入由get_qrcode方法生成的ticket参数
* @return string url 返回http地址
*/

function getQrRUL($ticket)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRUrl($ticket);
return $result;


}

get_qrcode( )创建二维码ticket

文档教程geeson 发表了文章 • 0 个评论 • 571 次浏览 • 2017-10-12 12:15 • 来自相关话题

/**
* 创建二维码ticket
* @param int|string $scene_id 自定义追踪id,临时二维码只能用数值型
* @param int $type 0:临时二维码;1:永久二维码(此时expire参数无效);2:永久二维码(此时expire参数无效)
* @param int $expire 临时二维码有效期,最大为604800秒

* @return array('ticket'=>'qrcode字串','expire_seconds'=>1800,'url'=>'二维码图片解析后的地址')
*/
function get_qrcode($scene_id, $type = 0, $expire = 1800)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRCode($scene_id, $type, $expire);
if (!$result) {
$return['errcode'] = 1001;
$return['errmsg'] = $weObj->errMsg;
// abort(500, lang('ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']));
ajaxMsg(0, 'ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']);
}
return $result;
} 查看全部
/**
* 创建二维码ticket
* @param int|string $scene_id 自定义追踪id,临时二维码只能用数值型
* @param int $type 0:临时二维码;1:永久二维码(此时expire参数无效);2:永久二维码(此时expire参数无效)
* @param int $expire 临时二维码有效期,最大为604800秒

* @return array('ticket'=>'qrcode字串','expire_seconds'=>1800,'url'=>'二维码图片解析后的地址')
*/
function get_qrcode($scene_id, $type = 0, $expire = 1800)
{
$weObj = getWechatActiveObj();
$result = $weObj->getQRCode($scene_id, $type, $expire);
if (!$result) {
$return['errcode'] = 1001;
$return['errmsg'] = $weObj->errMsg;
// abort(500, lang('ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']));
ajaxMsg(0, 'ErrCode:' . $return['errcode'] . ' ErrMsg: ' . $return['errmsg']);
}
return $result;
}

sendGroupMassMessage( ) 高级群发消息

文档教程geeson 发表了文章 • 0 个评论 • 512 次浏览 • 2017-10-12 12:14 • 来自相关话题

/**
* 高级群发消息, 根据群组id群发图文消息(认证后的订阅号可用)
* 注意:视频需要在调用uploadMedia()方法后,再使用 uploadMpVideo() 方法生成,
* 然后获得的 mediaid 才能用于群发,且消息类型为 mpvideo 类型。
* @param array $data 消息结构
* {
* "filter"=>array(
* "is_to_all"=>False, //是否群发给所有用户.True不用分组id,False需填写分组id
* "group_id"=>"2" //群发的分组id
* ),
* "msgtype"=>"mpvideo",
* // 在下面5种类型中选择对应的参数内容
* // mpnews | voice | image | mpvideo => array( "media_id"=>"MediaId")
* // text => array ( "content" => "hello")
* }
* @return boolean|array
*/
function sendGroupMassMessage($data)
{
$weObj = getWechatActiveObj();
$result = $weObj->sendGroupMassMessage($data);
if ($result) {
return $result;
} else {
$return['errCode'] = $weObj->errCode;
$return['errMsg'] = $weObj->errMsg;
return $return;
}
} 查看全部
/**
* 高级群发消息, 根据群组id群发图文消息(认证后的订阅号可用)
* 注意:视频需要在调用uploadMedia()方法后,再使用 uploadMpVideo() 方法生成,
* 然后获得的 mediaid 才能用于群发,且消息类型为 mpvideo 类型。
* @param array $data 消息结构
* {
* "filter"=>array(
* "is_to_all"=>False, //是否群发给所有用户.True不用分组id,False需填写分组id
* "group_id"=>"2" //群发的分组id
* ),
* "msgtype"=>"mpvideo",
* // 在下面5种类型中选择对应的参数内容
* // mpnews | voice | image | mpvideo => array( "media_id"=>"MediaId")
* // text => array ( "content" => "hello")
* }
* @return boolean|array
*/
function sendGroupMassMessage($data)
{
$weObj = getWechatActiveObj();
$result = $weObj->sendGroupMassMessage($data);
if ($result) {
return $result;
} else {
$return['errCode'] = $weObj->errCode;
$return['errMsg'] = $weObj->errMsg;
return $return;
}
}

replyNews( )回复图文

文档教程geeson 发表了文章 • 0 个评论 • 664 次浏览 • 2017-10-12 12:12 • 来自相关话题

/**
* 回复图文
* @author geeson myrhzq@qq.com
* @param $news array
数组结构:
array(
"0"=>array(
'Title'=>'msg title',
'Description'=>'Description text',
'PicUrl'=>'http://www.domain.com/1.jpg',
'Url'=>'http://www.domain.com/1.html'
),
"1"=>....
)
*/
function replyNews($new = [])
{
if (is_array($new)) {
$weObj = getWechatObj();
return $weObj->news($new)->reply();
}

} 查看全部
/**
* 回复图文
* @author geeson myrhzq@qq.com
* @param $news array
数组结构:
array(
"0"=>array(
'Title'=>'msg title',
'Description'=>'Description text',
'PicUrl'=>'http://www.domain.com/1.jpg',
'Url'=>'http://www.domain.com/1.html'
),
"1"=>....
)
*/
function replyNews($new = [])
{
if (is_array($new)) {
$weObj = getWechatObj();
return $weObj->news($new)->reply();
}

}

replyVideo( )回复视频消息

文档教程geeson 发表了文章 • 0 个评论 • 387 次浏览 • 2017-10-12 12:09 • 来自相关话题

/*
* 回复视频消息
* @param $mediaid string
* @param $title string
* @param $description string
*/
function replyVideo($mediaid = '', $title = '', $description = '')
{
$weObj = getWechatObj();
return $weObj->video($mediaid, $title, $description)->reply();
} 查看全部
/*
* 回复视频消息
* @param $mediaid string
* @param $title string
* @param $description string
*/
function replyVideo($mediaid = '', $title = '', $description = '')
{
$weObj = getWechatObj();
return $weObj->video($mediaid, $title, $description)->reply();
}

replyVoice( )回复语音消息

文档教程geeson 发表了文章 • 0 个评论 • 389 次浏览 • 2017-10-12 12:08 • 来自相关话题

/**
* 回复语音消息
* @param string media_id
*
*/
function replyVoice($media_id = '')
{
$weObj = getWechatObj();
return $weObj->voice($media_id)->reply();
} 查看全部
/**
* 回复语音消息
* @param string media_id
*
*/
function replyVoice($media_id = '')
{
$weObj = getWechatObj();
return $weObj->voice($media_id)->reply();
}

replyMusic( )回复音乐

文档教程geeson 发表了文章 • 0 个评论 • 375 次浏览 • 2017-10-12 12:08 • 来自相关话题

/**
* 设置回复音乐
* @param string $title
* @param string $desc
* @param string $musicurl
* @param string $hgmusicurl
* @param string $thumbmediaid 音乐图片缩略图的媒体id,非必须
*/
function replyMusic($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')
{
$weObj = getWechatObj();
return $weObj->music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')->reply();

} 查看全部
/**
* 设置回复音乐
* @param string $title
* @param string $desc
* @param string $musicurl
* @param string $hgmusicurl
* @param string $thumbmediaid 音乐图片缩略图的媒体id,非必须
*/
function replyMusic($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')
{
$weObj = getWechatObj();
return $weObj->music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')->reply();

}