<?php
/*
* PHPwork模块化工作台 - EasyWeChat
* EasyWeChat开发文档:https://www.easywechat.com/docs
*/
use EasyWeChat\Factory;
if( isset( $GLOBALS['config']['微信公众号'] ) ){
$GLOBALS['wechat']['config'] = [
'appid' => $GLOBALS['config']['微信公众号']['appid'],
'appsecret' => $GLOBALS['config']['微信公众号']['appsecret'],
'token' => $GLOBALS['config']['微信公众号']['token'],
'aes_key' => $GLOBALS['config']['微信公众号']['aes_key'],
];
$GLOBALS['wechat']['app'] = Factory::officialAccount([
'app_id' => $GLOBALS['config']['微信公众号']['appid'],
'secret' => $GLOBALS['config']['微信公众号']['appsecret'],
'token' => $GLOBALS['config']['微信公众号']['token'],
'aes_key' => $GLOBALS['config']['微信公众号']['aes_key'],
'response_type' => 'array',
]);
}
if( isset( $GLOBALS['config']['微信支付'] ) ){
$GLOBALS['wechat']['config']['mch_id'] = $GLOBALS['config']['微信支付']['mch_id'] ; //商户号
$GLOBALS['wechat']['config']['apikey'] = $GLOBALS['config']['微信支付']['apikey'] ; // API 密钥
$GLOBALS['wechat']['config']['notify_url'] = _APP_URL_ . '/data/pay/wechat/notify.php'; // 支付成功后回调地址
}
// 获得用户信息
if (!function_exists('wechat_oauth_userinfo')) {
function wechat_oauth_userinfo(){
// 未登录 这里应该保存到数据库里判断 有可能取消关注了不能简单判断数据库 ['snsapi_userinfo']
if ( isset($_SESSION['wechat_user']) && $_SESSION['wechat_user']!=''
&& isset($_SESSION['wechat_user']['original']['openid'])
&& $_SESSION['wechat_user']['original']['openid']!='' ){
if( !isset($GLOBALS['wechat']['member']) ){
//判断是否存在unionid
if(isset($_SESSION['wechat_user']['original']['unionid']) && $_SESSION['wechat_user']['original']['unionid']!=''){
$unionid=$_SESSION['wechat_user']['original']['unionid'];
//添加用户到系统用户表
$sql="select * from ".tablename('sys_member')." where unionid='".$unionid."' ";
}else{
$unionid=0;
//添加用户到系统用户表
$sql="select * from ".tablename('sys_member')." where openid='".$_SESSION['wechat_user']['original']['openid']."' ";
}
$member=$GLOBALS['db']->query($sql)->fetch(\PDO::FETCH_ASSOC);
//判断用户是否存在
if($member){
if(strpos( $member['unionid_openid'],$_SESSION['wechat_user']['original']['openid']) !== false){
//全局变量用户信息
$GLOBALS['wechat']['member']= $member;
}else{
if($member['unionid_openid']==''){
$data=['unionid_openid'=>$_SESSION['wechat_user']['original']['openid'].','];
}else{
$data=['unionid_openid'=> $member['unionid_openid'].$_SESSION['wechat_user']['original']['openid'].','];
}
if($unionid!=0){
//修改系统用户表的所有openid
pdo_update('sys_member',$data,['unionid'=>$unionid]);
}else{
//修改系统用户表的所有openid
pdo_update('sys_member',$data,['openid'=> $_SESSION['wechat_user']['original']['openid'] ]);
}
//全局变量用户信息
$GLOBALS['wechat']['member']= $member;
}
}else{
//添加用户信息
$data=array(
'nickname'=> $_SESSION['wechat_user']['nickname'],
'avatar'=> $_SESSION['wechat_user']['avatar'],
'openid'=> $_SESSION['wechat_user']['original']['openid'],
'unionid'=> $unionid,
'unionid_openid'=> $_SESSION['wechat_user']['original']['openid'].',',
'create_time'=> time(),
'status'=>1,
);
$ok = pdo_insert('sys_member',$data);
$GLOBALS['wechat']['member']=$GLOBALS['db']->query($sql)->fetch(\PDO::FETCH_ASSOC);
}
}
}else{
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ?"https://": "http://";
//$protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//$_SESSION['target_url'] = url( [ 'demo_wechat' ,'index','oauth','index.php'] );
$_SESSION['target_url'] = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$response = $GLOBALS['wechat']['app']->oauth->scopes(['snsapi_userinfo'])
->redirect( url( [ 'api' ,'wechat','oauth','index.php'] ) );
$response->send() ;
exit();
}
}
}
//获取小程序用户openid和unionid --- 手动调用(非自动加载)
if(!function_exists('wxapp_userinfo')){
function wxapp_userinfo($code){
$wxUrl = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$GLOBALS['config']['微信小程序']['appid'].'&secret='.$GLOBALS['config']['微信小程序']['appsecret'].'&js_code='.$code.'&grant_type=authorization_code';
$result = curl_get($wxUrl);//请求拼接好的url
$wxResult = json_decode($result, true);
if (empty($wxResult)) {
$arr['code']=$wxResult;
} else {
$loginFail = array_key_exists('errcode', $wxResult);
if ($loginFail) {//请求失败
$arr['code']=$loginFail;
} else {//请求成功
$arr['code']=200;
$arr['data'] = $wxResult;
}
}
return $arr;
}
}
//保存小程序用户信息 --- 手动调用(非自动加载)
if(!function_exists('wxapp_userinfo_save')){
function wxapp_userinfo_save($openid,$unionid,$nickname,$avatar){
$sys_user=pdo_fetch(" select * from ".tablename('sys_member')." where unionid='".$unionid."' ");
if($sys_user){
if(strpos( $sys_user['unionid_openid'],$openid) !== false){
$arr['code']=200;
$arr['message']='用户信息获取成功!';
$arr['data']=$sys_user;
}else{
if($sys_user['unionid_openid']==''){
$data=['unionid_openid'=>$openid.','];
}else{
$data=['unionid_openid'=>$sys_user['unionid_openid'].$openid.','];
}
//修改系统用户表的所有openid
$ok=pdo_update('sys_member',$data,['unionid'=>$unionid]);
if($ok){
$arr['code']=200;
$arr['message']='用户信息获取成功!';
$arr['data']=$sys_user;
}else{
$arr['code']=400;
$arr['message']='用户信息插入失败,请重试!';
$arr['data']=$sys_user;
}
}
}else{
//添加用户信息
$data=array(
'nickname'=> $nickname,
'avatar'=> $avatar,
'openid'=> $openid,
'unionid'=> $unionid,
'unionid_openid'=> $openid.',',
'create_time'=>
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
微信公众号程序,必须微信认证服务号,微信支付商家 客户扫码,打开商家定义支付页面,输入金额和对应定义信息,提交微信支付,实现快速付款 支持创建多个店铺,各个店铺自定义不同自定义表单。通过自定义表单实现订单自定义明细 通过店铺自定义表单可以轻松建立,快捷收款、微信收银台、面对面收款、商品预约预订等扫码微信支付,提升客户服务体验,商户快速获得精准订单数据,实现账款统计。 通过打开自定义的表单页面,输入自定义的指定信息,可以实现订单收款。 完全可自定义的表单字段,支持单行文本,多行文本,单选,多选,下拉选择,上传图片,时间。 收款金额可设置为固定金额或输入金额。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 8 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
破碎的天堂鸟
- 粉丝: 5727
- 资源: 1448
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)