微信公众平台开发(122) 获取微信会员卡用户姓名和手机号

时间:2018-05-10 21:37:29   收藏:0   阅读:2638

 

1. SDK接口定义

    
    //拉取会员信息接口
    public function get_membercard_userinfo($msg)
    {
        $url = "https://api.weixin.qq.com/card/membercard/userinfo/get?access_token=".$this->access_token;
        $res = $this->http_request($url, json_encode($msg));
        return json_decode($res, true);
    }

 

2. 接收事件submit_membercard_user_info

            case "submit_membercard_user_info":
                $msg = array(‘code‘ => strval($object->UserCardCode),
                              ‘card_id‘ => strval($object->CardId)
                             );
                $content = $weixin->get_membercard_userinfo($msg);
                $data = array();
                foreach ($content[‘user_info‘][‘common_field_list‘] as &$item) {
                    if ($item[‘name‘] == "USER_FORM_INFO_FLAG_MOBILE"){
                        $data[‘mobile‘] = $item["value"];
                    }
                    if ($item[‘name‘] == "USER_FORM_INFO_FLAG_NAME"){
                        $data[‘surname‘] = $item["value"];
                    }
                }
                $User->where("`openid` = ‘".$openid."‘")->save($data);
                break;

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!