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

 

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;

 

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

上一篇:微信公众号开发流程


下一篇:复习java基础第四天(集合)