• token获取
    $token = WeAccount::token();
  • 加载类

$weixin = weixinpay::create('wechat');
$userinfo = $weixin->getOauthInfo();
load()->model('mc');

$wechat = $_W['account']['setting']['payment']['wechat'];//支付设置
$wechat =(!empty($wechat['borrow']))? uni_setting($wechat['borrow'], array('payment'))['payment']['wechat']:$wechat;
  • 长网址转换短网址

    load()->classs('weixin.account');
    $acc = WeiXinAccount::create($_W['acid']);
    $url = $acc->long2short("http://www.baidu.com")['short_url'];
  • 文件上传,返回media_id

    if(is_file(ATTACHMENT_ROOT."/1.jpg")){
        $path ="1.jpg";
    }else{
      load()->func('file');
       file_move(MODULE_ROOT."/1.jpg",ATTACHMENT_ROOT."/1.jpg");
       $path ="1.jpg";
    }
    load()->classs('weixin.account');
          $acc = WeiXinAccount::create($_W['acid']);
          $media = $acc->uploadMedia($path);
          dump($media);
    Array
    (
      [type] => image
      [media_id] => 4IftJVo5o-qS2hm0Q0ID-_m5VARGL2eqKsgT1ih7v63SA8pULoqplVzIEU4hdt7y
      [created_at] => 1515481289
    )
  • 下载文件

        load()->classs('weixin.account');
        $acc = WeiXinAccount::create($_W['acid']);
        $arr = ['media_id'=>"4IftJVo5o-qS2hm0Q0ID-_m5VARGL2eqKsgT1ih7v63SA8pULoqplVzIEU4hdt7y",'type'=>"image"];
        $media = $acc->downloadMedia($arr);
        //images/5/2018/01/4IftJVo5o-qS2hm0Q0ID-_m5VARGL2eqKsgT1ih7v63SA8pULoqplVzIEU4hdt7y.jpg 返回路径
  • 读取与写入实实配置
$config = pdo_getcolumn('uni_account_modules',[
            'module' => 模块名,
            'uniacid' => $_W['uniacid']
        ],'settings');
$config = iunserializer($config);
pdo_update('uni_account_modules',[
                'settings' =>iserializer($config),
            ], [
                'module' =>模块名,
                'uniacid' =>  $_W['uniacid']
            ]);
  • 发送客服消息
      $info = "我是客服消息:\n 欢迎使用";
    $openid = "ocUeXwINHvRqWPSldYZVO4dA_CzI";
    $message = [
          'msgtype'=>'text',
          'text'=>['content'=>urlencode($info)],
          'touser'=>$openid
          ];
    $acc = WeAccount::create();
    $status = $acc->sendCustomNotice($message);
    if (is_error($status)) {
     message('发送失败,原因为' . $status['message']);
    }  
    $message = [
      'touser' => $openid,
      'msgtype' => 'image',
      'image' =>['media_id'=> 'MEDIA_ID']//微信素材media_id,微擎中微信上传组件可以得到此值
    ];
    $message = [
      'touser' => $openid,
      'msgtype' => 'music',
      'music' => [
          'title' => '标题',
          'description' => '描述'
          'musicurl' => '音乐文件URL',
          'hqmusicurl' => '高清音乐文件URL',
          'thumb_media_id' => 'MEDIA_ID',
      ]
    ];
    $message = [
      'touser' => $openid,
      'msgtype' => 'news',
      'news' =>[
          [
              'title' => '标题',
              'description' => '描述',
              'url' : '链接',
              'picurl' : '封面图片地址'
          ],
          [
              'title' => '标题1',
              'description' => '描述1',
              'url' : '链接',
              'picurl' : '封面图片地址'
          ],
    ]
    ];
    $message = [
      'touser' => $openid,
      'msgtype' => 'wxcard',
      'wxcard' => ['card_id'=> 'CARD_ID']
    ];
  • 发送模板消息
      $tpl_id = "QDDIbJpHEann2VeN12r6GXf0OiTJMky8uL4FAK2zAp8";
    $openid = "ocUeXwINHvRqWPSldYZVO4dA_CzI";
    $url = "";
    $arr  =[];
    $sendarr =['测试通知标题','西安大学','管理员','2018-4-28','商城决定展示关闭','点击查看详情'];
    $tpl = '{{first.DATA}}
    学校:{{keyword1.DATA}}
    通知人:{{keyword2.DATA}}
    时间:{{keyword3.DATA}}
    通知内容:{{keyword4.DATA}}';
    preg_match_all('/{{(.*).DATA}}/',$tpl,$rs);
    foreach($rs[1] as  $k=>$v){
          $arr[$v] = array(
          'value'=>$sendarr[$k]
          );
          }
          $arr['first']['color']='#04be02';
          $arr['remark']['color']='#18b4ed';
    $acc = WeAccount::create();
    $status = $acc->sendTplNotice($openid,$tpl_id, $arr, $url); //1表示发送成功   
  • 获取用户信息oauth
     load()->classs('weixin.account');
     $acc = WeiXinAccount::create($_W['acid']);
      $userinfo =$acc->fansQueryInfo($openid);    
作者:Yoby  创建时间:2020-07-23 22:40
 更新时间:2024-12-05 13:26
上一篇:
下一篇: