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;