12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340 |
- <?php
- class Wechat
- {
- const MSGTYPE_TEXT = 'text';
- const MSGTYPE_IMAGE = 'image';
- const MSGTYPE_LOCATION = 'location';
- const MSGTYPE_LINK = 'link';
- const MSGTYPE_EVENT = 'event';
- const MSGTYPE_MUSIC = 'music';
- const MSGTYPE_NEWS = 'news';
- const MSGTYPE_VOICE = 'voice';
- const MSGTYPE_VIDEO = 'video';
- const EVENT_SUBSCRIBE = 'subscribe';
- const EVENT_UNSUBSCRIBE = 'unsubscribe';
- const EVENT_SCAN = 'SCAN';
- const EVENT_LOCATION = 'LOCATION';
- const EVENT_MENU_VIEW = 'VIEW';
- const EVENT_MENU_CLICK = 'CLICK';
- const EVENT_MENU_SCAN_PUSH = 'scancode_push';
- const EVENT_MENU_SCAN_WAITMSG = 'scancode_waitmsg';
- const EVENT_MENU_PIC_SYS = 'pic_sysphoto';
- const EVENT_MENU_PIC_PHOTO = 'pic_photo_or_album';
- const EVENT_MENU_PIC_WEIXIN = 'pic_weixin';
- const EVENT_MENU_LOCATION = 'location_select';
- const EVENT_SEND_MASS = 'MASSSENDJOBFINISH';
- const EVENT_SEND_TEMPLATE = 'TEMPLATESENDJOBFINISH';
- const EVENT_KF_SEESION_CREATE = 'kfcreatesession';
- const EVENT_KF_SEESION_CLOSE = 'kfclosesession';
- const EVENT_KF_SEESION_SWITCH = 'kfswitchsession';
- const EVENT_CARD_PASS = 'card_pass_check';
- const EVENT_CARD_NOTPASS = 'card_not_pass_check';
- const EVENT_CARD_USER_GET = 'user_get_card';
- const EVENT_CARD_USER_DEL = 'user_del_card';
- const API_URL_PREFIX = 'https://api.weixin.qq.com/cgi-bin';
- const AUTH_URL = '/token?grant_type=client_credential&';
- const MENU_CREATE_URL = '/menu/create?';
- const MENU_GET_URL = '/menu/get?';
- const MENU_DELETE_URL = '/menu/delete?';
- const GET_TICKET_URL = '/ticket/getticket?';
- const CALLBACKSERVER_GET_URL = '/getcallbackip?';
- const QRCODE_CREATE_URL='/qrcode/create?';
- const QR_SCENE = 0;
- const QR_LIMIT_SCENE = 1;
- const QRCODE_IMG_URL='https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=';
- const SHORT_URL='/shorturl?';
- const USER_GET_URL='/user/get?';
- const USER_INFO_URL='/user/info?';
- const USER_UPDATEREMARK_URL='/user/info/updateremark?';
- const GROUP_GET_URL='/groups/get?';
- const USER_GROUP_URL='/groups/getid?';
- const GROUP_CREATE_URL='/groups/create?';
- const GROUP_UPDATE_URL='/groups/update?';
- const GROUP_MEMBER_UPDATE_URL='/groups/members/update?';
- const GROUP_MEMBER_BATCHUPDATE_URL='/groups/members/batchupdate?';
- const CUSTOM_SEND_URL='/message/custom/send?';
- const MEDIA_UPLOADNEWS_URL = '/media/uploadnews?';
- const MASS_SEND_URL = '/message/mass/send?';
- const TEMPLATE_SET_INDUSTRY_URL = '/message/template/api_set_industry?';
- const TEMPLATE_ADD_TPL_URL = '/message/template/api_add_template?';
- const TEMPLATE_SEND_URL = '/message/template/send?';
- const MASS_SEND_GROUP_URL = '/message/mass/sendall?';
- const MASS_DELETE_URL = '/message/mass/delete?';
- const MASS_PREVIEW_URL = '/message/mass/preview?';
- const MASS_QUERY_URL = '/message/mass/get?';
- const UPLOAD_MEDIA_URL = 'http://file.api.weixin.qq.com/cgi-bin';
- const MEDIA_UPLOAD_URL = '/media/upload?';
- const MEDIA_UPLOADIMG_URL = '/media/uploadimg?';
- const MEDIA_GET_URL = '/media/get?';
- const MEDIA_VIDEO_UPLOAD = '/media/uploadvideo?';
- const MEDIA_FOREVER_UPLOAD_URL = '/material/add_material?';
- const MEDIA_FOREVER_NEWS_UPLOAD_URL = '/material/add_news?';
- const MEDIA_FOREVER_NEWS_UPDATE_URL = '/material/update_news?';
- const MEDIA_FOREVER_GET_URL = '/material/get_material?';
- const MEDIA_FOREVER_DEL_URL = '/material/del_material?';
- const MEDIA_FOREVER_COUNT_URL = '/material/get_materialcount?';
- const MEDIA_FOREVER_BATCHGET_URL = '/material/batchget_material?';
- const OAUTH_PREFIX = 'https://open.weixin.qq.com/connect/oauth2';
- const OAUTH_AUTHORIZE_URL = '/authorize?';
-
- const CUSTOM_SERVICE_GET_RECORD = '/customservice/getrecord?';
- const CUSTOM_SERVICE_GET_KFLIST = '/customservice/getkflist?';
- const CUSTOM_SERVICE_GET_ONLINEKFLIST = '/customservice/getonlinekflist?';
- const API_BASE_URL_PREFIX = 'https://api.weixin.qq.com';
- const OAUTH_TOKEN_URL = '/sns/oauth2/access_token?';
- const OAUTH_REFRESH_URL = '/sns/oauth2/refresh_token?';
- const OAUTH_USERINFO_URL = '/sns/userinfo?';
- const OAUTH_AUTH_URL = '/sns/auth?';
-
- const CUSTOM_SESSION_CREATE = '/customservice/kfsession/create?';
- const CUSTOM_SESSION_CLOSE = '/customservice/kfsession/close?';
- const CUSTOM_SESSION_SWITCH = '/customservice/kfsession/switch?';
- const CUSTOM_SESSION_GET = '/customservice/kfsession/getsession?';
- const CUSTOM_SESSION_GET_LIST = '/customservice/kfsession/getsessionlist?';
- const CUSTOM_SESSION_GET_WAIT = '/customservice/kfsession/getwaitcase?';
- const CS_KF_ACCOUNT_ADD_URL = '/customservice/kfaccount/add?';
- const CS_KF_ACCOUNT_UPDATE_URL = '/customservice/kfaccount/update?';
- const CS_KF_ACCOUNT_DEL_URL = '/customservice/kfaccount/del?';
- const CS_KF_ACCOUNT_UPLOAD_HEADIMG_URL = '/customservice/kfaccount/uploadheadimg?';
-
- const CARD_CREATE = '/card/create?';
- const CARD_DELETE = '/card/delete?';
- const CARD_UPDATE = '/card/update?';
- const CARD_GET = '/card/get?';
- const CARD_BATCHGET = '/card/batchget?';
- const CARD_MODIFY_STOCK = '/card/modifystock?';
- const CARD_LOCATION_BATCHADD = '/card/location/batchadd?';
- const CARD_LOCATION_BATCHGET = '/card/location/batchget?';
- const CARD_GETCOLORS = '/card/getcolors?';
- const CARD_QRCODE_CREATE = '/card/qrcode/create?';
- const CARD_CODE_CONSUME = '/card/code/consume?';
- const CARD_CODE_DECRYPT = '/card/code/decrypt?';
- const CARD_CODE_GET = '/card/code/get?';
- const CARD_CODE_UPDATE = '/card/code/update?';
- const CARD_CODE_UNAVAILABLE = '/card/code/unavailable?';
- const CARD_TESTWHILELIST_SET = '/card/testwhitelist/set?';
- const CARD_MEMBERCARD_ACTIVATE = '/card/membercard/activate?';
- const CARD_MEMBERCARD_UPDATEUSER = '/card/membercard/updateuser?';
- const CARD_MOVIETICKET_UPDATEUSER = '/card/movieticket/updateuser?';
- const CARD_BOARDINGPASS_CHECKIN = '/card/boardingpass/checkin?';
- const CARD_LUCKYMONEY_UPDATE = '/card/luckymoney/updateuserbalance?';
- const SEMANTIC_API_URL = '/semantic/semproxy/search?';
-
- static $DATACUBE_URL_ARR = array(
- 'user' => array(
- 'summary' => '/datacube/getusersummary?',
- 'cumulate' => '/datacube/getusercumulate?',
- ),
- 'article' => array(
- 'summary' => '/datacube/getarticlesummary?',
- 'total' => '/datacube/getarticletotal?',
- 'read' => '/datacube/getuserread?',
- 'readhour' => '/datacube/getuserreadhour?',
- 'share' => '/datacube/getusershare?',
- 'sharehour' => '/datacube/getusersharehour?',
- ),
- 'upstreammsg' => array(
- 'summary' => '/datacube/getupstreammsg?',
- 'hour' => '/datacube/getupstreammsghour?',
- 'week' => '/datacube/getupstreammsgweek?',
- 'month' => '/datacube/getupstreammsgmonth?',
- 'dist' => '/datacube/getupstreammsgdist?',
- 'distweek' => '/datacube/getupstreammsgdistweek?',
- 'distmonth' => '/datacube/getupstreammsgdistmonth?',
- ),
- 'interface' => array(
- 'summary' => '/datacube/getinterfacesummary?',
- 'summaryhour' => '/datacube/getinterfacesummaryhour?',
- )
- );
-
- const SHAKEAROUND_DEVICE_APPLYID = '/shakearound/device/applyid?';
- const SHAKEAROUND_DEVICE_UPDATE = '/shakearound/device/update?';
- const SHAKEAROUND_DEVICE_SEARCH = '/shakearound/device/search?';
- const SHAKEAROUND_DEVICE_BINDLOCATION = '/shakearound/device/bindlocation?';
- const SHAKEAROUND_DEVICE_BINDPAGE = '/shakearound/device/bindpage?';
- const SHAKEAROUND_MATERIAL_ADD = '/shakearound/material/add?';
- const SHAKEAROUND_PAGE_ADD = '/shakearound/page/add?';
- const SHAKEAROUND_PAGE_UPDATE = '/shakearound/page/update?';
- const SHAKEAROUND_PAGE_SEARCH = '/shakearound/page/search?';
- const SHAKEAROUND_PAGE_DELETE = '/shakearound/page/delete?';
- const SHAKEAROUND_USER_GETSHAKEINFO = '/shakearound/user/getshakeinfo?';
- const SHAKEAROUND_STATISTICS_DEVICE = '/shakearound/statistics/device?';
- const SHAKEAROUND_STATISTICS_PAGE = '/shakearound/statistics/page?';
- private $token;
- private $encodingAesKey;
- private $encrypt_type;
- private $appid;
- private $appsecret;
- private $access_token;
- private $jsapi_ticket;
- private $user_token;
- private $partnerid;
- private $partnerkey;
- private $paysignkey;
- private $postxml;
- private $_msg;
- private $_funcflag = false;
- private $_receive;
- private $_text_filter = true;
- public $debug = false;
- public $errCode = 40001;
- public $errMsg = "no access";
- public $logcallback;
- public function __construct($options)
- {
- $this->token = isset($options['token'])?$options['token']:'';
- $this->encodingAesKey = isset($options['encodingaeskey'])?$options['encodingaeskey']:'';
- $this->appid = isset($options['appid'])?$options['appid']:'';
- $this->appsecret = isset($options['appsecret'])?$options['appsecret']:'';
- $this->debug = isset($options['debug'])?$options['debug']:false;
- $this->logcallback = isset($options['logcallback'])?$options['logcallback']:false;
- }
-
- private function checkSignature($str='')
- {
- $signature = isset($_GET["signature"])?$_GET["signature"]:'';
- $signature = isset($_GET["msg_signature"])?$_GET["msg_signature"]:$signature;
- $timestamp = isset($_GET["timestamp"])?$_GET["timestamp"]:'';
- $nonce = isset($_GET["nonce"])?$_GET["nonce"]:'';
- $token = $this->token;
- $tmpArr = array($token, $timestamp, $nonce,$str);
- sort($tmpArr, SORT_STRING);
- $tmpStr = implode( $tmpArr );
- $tmpStr = sha1( $tmpStr );
- if( $tmpStr == $signature ){
- return true;
- }else{
- return false;
- }
- }
-
- public function valid($return=false)
- {
- $encryptStr="";
- if ($_SERVER['REQUEST_METHOD'] == "POST") {
- $postStr = file_get_contents("php://input");
- $array = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- $this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"]: '';
- if ($this->encrypt_type == 'aes') {
- $this->log($postStr);
- $encryptStr = $array['Encrypt'];
- $pc = new Prpcrypt($this->encodingAesKey);
- $array = $pc->decrypt($encryptStr,$this->appid);
- if (!isset($array[0]) || ($array[0] != 0)) {
- if (!$return) {
- die('decrypt error!');
- } else {
- return false;
- }
- }
- $this->postxml = $array[1];
- if (!$this->appid)
- $this->appid = $array[2];
- } else {
- $this->postxml = $postStr;
- }
- } elseif (isset($_GET["echostr"])) {
- $echoStr = $_GET["echostr"];
- if ($return) {
- if ($this->checkSignature())
- return $echoStr;
- else
- return false;
- } else {
- if ($this->checkSignature())
- die($echoStr);
- else
- die('no access');
- }
- }
- if (!$this->checkSignature($encryptStr)) {
- if ($return)
- return false;
- else
- die('no access');
- }
- return true;
- }
-
- public function Message($msg = '',$append = false){
- if (is_null($msg)) {
- $this->_msg =array();
- }elseif (is_array($msg)) {
- if ($append)
- $this->_msg = array_merge($this->_msg,$msg);
- else
- $this->_msg = $msg;
- return $this->_msg;
- } else {
- return $this->_msg;
- }
- }
-
- public function setFuncFlag($flag) {
- $this->_funcflag = $flag;
- return $this;
- }
-
- protected function log($log){
- if ($this->debug && function_exists($this->logcallback)) {
- if (is_array($log)) $log = print_r($log,true);
- return call_user_func($this->logcallback,$log);
- }
- }
-
- public function getRev()
- {
- if ($this->_receive) return $this;
- $postStr = !empty($this->postxml)?$this->postxml:file_get_contents("php://input");
-
- $this->log($postStr);
- if (!empty($postStr)) {
- $this->_receive = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- }
- return $this;
- }
-
- public function getRevData()
- {
- return $this->_receive;
- }
-
- public function getRevFrom() {
- if (isset($this->_receive['FromUserName']))
- return $this->_receive['FromUserName'];
- else
- return false;
- }
-
- public function getRevTo() {
- if (isset($this->_receive['ToUserName']))
- return $this->_receive['ToUserName'];
- else
- return false;
- }
-
- public function getRevType() {
- if (isset($this->_receive['MsgType']))
- return $this->_receive['MsgType'];
- else
- return false;
- }
-
- public function getRevID() {
- if (isset($this->_receive['MsgId']))
- return $this->_receive['MsgId'];
- else
- return false;
- }
-
- public function getRevCtime() {
- if (isset($this->_receive['CreateTime']))
- return $this->_receive['CreateTime'];
- else
- return false;
- }
-
- public function getRevContent(){
- if (isset($this->_receive['Content']))
- return $this->_receive['Content'];
- else if (isset($this->_receive['Recognition']))
- return $this->_receive['Recognition'];
- else
- return false;
- }
-
- public function getRevPic(){
- if (isset($this->_receive['PicUrl']))
- return array(
- 'mediaid'=>$this->_receive['MediaId'],
- 'picurl'=>(string)$this->_receive['PicUrl'],
- );
- else
- return false;
- }
-
- public function getRevLink(){
- if (isset($this->_receive['Url'])){
- return array(
- 'url'=>$this->_receive['Url'],
- 'title'=>$this->_receive['Title'],
- 'description'=>$this->_receive['Description']
- );
- } else
- return false;
- }
-
- public function getRevGeo(){
- if (isset($this->_receive['Location_X'])){
- return array(
- 'x'=>$this->_receive['Location_X'],
- 'y'=>$this->_receive['Location_Y'],
- 'scale'=>$this->_receive['Scale'],
- 'label'=>$this->_receive['Label']
- );
- } else
- return false;
- }
-
- public function getRevEventGeo(){
- if (isset($this->_receive['Latitude'])){
- return array(
- 'x'=>$this->_receive['Latitude'],
- 'y'=>$this->_receive['Longitude'],
- 'precision'=>$this->_receive['Precision'],
- );
- } else
- return false;
- }
-
- public function getRevEvent(){
- if (isset($this->_receive['Event'])){
- $array['event'] = $this->_receive['Event'];
- }
- if (isset($this->_receive['EventKey'])){
- $array['key'] = $this->_receive['EventKey'];
- }
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
-
- public function getRevScanInfo(){
- if (isset($this->_receive['ScanCodeInfo'])){
- if (!is_array($this->_receive['ScanCodeInfo'])) {
- $array=(array)$this->_receive['ScanCodeInfo'];
- $this->_receive['ScanCodeInfo']=$array;
- }else {
- $array=$this->_receive['ScanCodeInfo'];
- }
- }
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
-
- public function getRevSendPicsInfo(){
- if (isset($this->_receive['SendPicsInfo'])){
- if (!is_array($this->_receive['SendPicsInfo'])) {
- $array=(array)$this->_receive['SendPicsInfo'];
- if (isset($array['PicList'])){
- $array['PicList']=(array)$array['PicList'];
- $item=$array['PicList']['item'];
- $array['PicList']['item']=array();
- foreach ( $item as $key => $value ){
- $array['PicList']['item'][$key]=(array)$value;
- }
- }
- $this->_receive['SendPicsInfo']=$array;
- } else {
- $array=$this->_receive['SendPicsInfo'];
- }
- }
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
-
- public function getRevSendGeoInfo(){
- if (isset($this->_receive['SendLocationInfo'])){
- if (!is_array($this->_receive['SendLocationInfo'])) {
- $array=(array)$this->_receive['SendLocationInfo'];
- if (empty($array['Poiname'])) {
- $array['Poiname']="";
- }
- if (empty($array['Label'])) {
- $array['Label']="";
- }
- $this->_receive['SendLocationInfo']=$array;
- } else {
- $array=$this->_receive['SendLocationInfo'];
- }
- }
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
-
- public function getRevVoice(){
- if (isset($this->_receive['MediaId'])){
- return array(
- 'mediaid'=>$this->_receive['MediaId'],
- 'format'=>$this->_receive['Format'],
- );
- } else
- return false;
- }
-
- public function getRevVideo(){
- if (isset($this->_receive['MediaId'])){
- return array(
- 'mediaid'=>$this->_receive['MediaId'],
- 'thumbmediaid'=>$this->_receive['ThumbMediaId']
- );
- } else
- return false;
- }
-
- public function getRevTicket(){
- if (isset($this->_receive['Ticket'])){
- return $this->_receive['Ticket'];
- } else
- return false;
- }
-
- public function getRevSceneId (){
- if (isset($this->_receive['EventKey'])){
- return str_replace('qrscene_','',$this->_receive['EventKey']);
- } else{
- return false;
- }
- }
-
- public function getRevTplMsgID(){
- if (isset($this->_receive['MsgID'])){
- return $this->_receive['MsgID'];
- } else
- return false;
- }
-
- public function getRevStatus(){
- if (isset($this->_receive['Status'])){
- return $this->_receive['Status'];
- } else
- return false;
- }
-
- public function getRevResult(){
- if (isset($this->_receive['Status']))
- $array['Status'] = $this->_receive['Status'];
- if (isset($this->_receive['MsgID']))
- $array['MsgID'] = $this->_receive['MsgID'];
-
- if (isset($this->_receive['TotalCount']))
- $array['TotalCount'] = $this->_receive['TotalCount'];
- if (isset($this->_receive['FilterCount']))
- $array['FilterCount'] = $this->_receive['FilterCount'];
- if (isset($this->_receive['SentCount']))
- $array['SentCount'] = $this->_receive['SentCount'];
- if (isset($this->_receive['ErrorCount']))
- $array['ErrorCount'] = $this->_receive['ErrorCount'];
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
-
- public function getRevKFCreate(){
- if (isset($this->_receive['KfAccount'])){
- return $this->_receive['KfAccount'];
- } else
- return false;
- }
-
- public function getRevKFClose(){
- if (isset($this->_receive['KfAccount'])){
- return $this->_receive['KfAccount'];
- } else
- return false;
- }
-
- public function getRevKFSwitch(){
- if (isset($this->_receive['FromKfAccount']))
- $array['FromKfAccount'] = $this->_receive['FromKfAccount'];
- if (isset($this->_receive['ToKfAccount']))
- $array['ToKfAccount'] = $this->_receive['ToKfAccount'];
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
-
- public function getRevCardPass(){
- if (isset($this->_receive['CardId']))
- return $this->_receive['CardId'];
- else
- return false;
- }
-
- public function getRevCardGet(){
- if (isset($this->_receive['CardId']))
- $array['CardId'] = $this->_receive['CardId'];
- if (isset($this->_receive['IsGiveByFriend']))
- $array['IsGiveByFriend'] = $this->_receive['IsGiveByFriend'];
- if (isset($this->_receive['UserCardCode']) && !empty($this->_receive['UserCardCode']))
- $array['UserCardCode'] = $this->_receive['UserCardCode'];
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
-
- public function getRevCardDel(){
- if (isset($this->_receive['CardId']))
- $array['CardId'] = $this->_receive['CardId'];
- if (isset($this->_receive['UserCardCode']) && !empty($this->_receive['UserCardCode']))
- $array['UserCardCode'] = $this->_receive['UserCardCode'];
- if (isset($array) && count($array) > 0) {
- return $array;
- } else {
- return false;
- }
- }
- public static function xmlSafeStr($str)
- {
- return '<![CDATA['.preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/",'',$str).']]>';
- }
-
- public static function data_to_xml($data) {
- $xml = '';
- foreach ($data as $key => $val) {
- is_numeric($key) && $key = "item id=\"$key\"";
- $xml .= "<$key>";
- $xml .= ( is_array($val) || is_object($val)) ? self::data_to_xml($val) : self::xmlSafeStr($val);
- list($key, ) = explode(' ', $key);
- $xml .= "</$key>";
- }
- return $xml;
- }
-
- public function xml_encode($data, $root='xml', $item='item', $attr='', $id='id', $encoding='utf-8') {
- if(is_array($attr)){
- $_attr = array();
- foreach ($attr as $key => $value) {
- $_attr[] = "{$key}=\"{$value}\"";
- }
- $attr = implode(' ', $_attr);
- }
- $attr = trim($attr);
- $attr = empty($attr) ? '' : " {$attr}";
- $xml = "<{$root}{$attr}>";
- $xml .= self::data_to_xml($data, $item, $id);
- $xml .= "</{$root}>";
- return $xml;
- }
-
- private function _auto_text_filter($text) {
- if (!$this->_text_filter) return $text;
- return str_replace("\r\n", "\n", $text);
- }
-
- public function text($text='')
- {
- $FuncFlag = $this->_funcflag ? 1 : 0;
- $msg = array(
- 'ToUserName' => $this->getRevFrom(),
- 'FromUserName'=>$this->getRevTo(),
- 'MsgType'=>self::MSGTYPE_TEXT,
- 'Content'=>$this->_auto_text_filter($text),
- 'CreateTime'=>time(),
- 'FuncFlag'=>$FuncFlag
- );
- $this->Message($msg);
- return $this;
- }
-
- public function image($mediaid='')
- {
- $FuncFlag = $this->_funcflag ? 1 : 0;
- $msg = array(
- 'ToUserName' => $this->getRevFrom(),
- 'FromUserName'=>$this->getRevTo(),
- 'MsgType'=>self::MSGTYPE_IMAGE,
- 'Image'=>array('MediaId'=>$mediaid),
- 'CreateTime'=>time(),
- 'FuncFlag'=>$FuncFlag
- );
- $this->Message($msg);
- return $this;
- }
-
- public function voice($mediaid='')
- {
- $FuncFlag = $this->_funcflag ? 1 : 0;
- $msg = array(
- 'ToUserName' => $this->getRevFrom(),
- 'FromUserName'=>$this->getRevTo(),
- 'MsgType'=>self::MSGTYPE_VOICE,
- 'Voice'=>array('MediaId'=>$mediaid),
- 'CreateTime'=>time(),
- 'FuncFlag'=>$FuncFlag
- );
- $this->Message($msg);
- return $this;
- }
-
- public function video($mediaid='',$title='',$description='')
- {
- $FuncFlag = $this->_funcflag ? 1 : 0;
- $msg = array(
- 'ToUserName' => $this->getRevFrom(),
- 'FromUserName'=>$this->getRevTo(),
- 'MsgType'=>self::MSGTYPE_VIDEO,
- 'Video'=>array(
- 'MediaId'=>$mediaid,
- 'Title'=>$title,
- 'Description'=>$description
- ),
- 'CreateTime'=>time(),
- 'FuncFlag'=>$FuncFlag
- );
- $this->Message($msg);
- return $this;
- }
-
- public function music($title,$desc,$musicurl,$hgmusicurl='',$thumbmediaid='') {
- $FuncFlag = $this->_funcflag ? 1 : 0;
- $msg = array(
- 'ToUserName' => $this->getRevFrom(),
- 'FromUserName'=>$this->getRevTo(),
- 'CreateTime'=>time(),
- 'MsgType'=>self::MSGTYPE_MUSIC,
- 'Music'=>array(
- 'Title'=>$title,
- 'Description'=>$desc,
- 'MusicUrl'=>$musicurl,
- 'HQMusicUrl'=>$hgmusicurl
- ),
- 'FuncFlag'=>$FuncFlag
- );
- if ($thumbmediaid) {
- $msg['Music']['ThumbMediaId'] = $thumbmediaid;
- }
- $this->Message($msg);
- return $this;
- }
-
- public function news($newsData=array())
- {
- $FuncFlag = $this->_funcflag ? 1 : 0;
- $count = count($newsData);
- $msg = array(
- 'ToUserName' => $this->getRevFrom(),
- 'FromUserName'=>$this->getRevTo(),
- 'MsgType'=>self::MSGTYPE_NEWS,
- 'CreateTime'=>time(),
- 'ArticleCount'=>$count,
- 'Articles'=>$newsData,
- 'FuncFlag'=>$FuncFlag
- );
- $this->Message($msg);
- return $this;
- }
-
- public function reply($msg=array(),$return = false)
- {
- if (empty($msg)) {
- if (empty($this->_msg))
- return false;
- $msg = $this->_msg;
- }
- $xmldata= $this->xml_encode($msg);
- $this->log($xmldata);
- if ($this->encrypt_type == 'aes') {
- $pc = new Prpcrypt($this->encodingAesKey);
- $array = $pc->encrypt($xmldata, $this->appid);
- $ret = $array[0];
- if ($ret != 0) {
- $this->log('encrypt err!');
- return false;
- }
- $timestamp = time();
- $nonce = rand(77,999)*rand(605,888)*rand(11,99);
- $encrypt = $array[1];
- $tmpArr = array($this->token, $timestamp, $nonce,$encrypt);
- sort($tmpArr, SORT_STRING);
- $signature = implode($tmpArr);
- $signature = sha1($signature);
- $xmldata = $this->generate($encrypt, $signature, $timestamp, $nonce);
- $this->log($xmldata);
- }
- if ($return)
- return $xmldata;
- else
- echo $xmldata;
- }
-
- private function generate($encrypt, $signature, $timestamp, $nonce)
- {
-
- $format = "<xml>
- <Encrypt><![CDATA[%s]]></Encrypt>
- <MsgSignature><![CDATA[%s]]></MsgSignature>
- <TimeStamp>%s</TimeStamp>
- <Nonce><![CDATA[%s]]></Nonce>
- </xml>";
- return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
- }
-
- private function http_get($url){
- $oCurl = curl_init();
- if(stripos($url,"https://")!==FALSE){
- curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($oCurl, CURLOPT_SSLVERSION, 1);
- }
- curl_setopt($oCurl, CURLOPT_URL, $url);
- curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
- $sContent = curl_exec($oCurl);
- $aStatus = curl_getinfo($oCurl);
- curl_close($oCurl);
- if(intval($aStatus["http_code"])==200){
- return $sContent;
- }else{
- return false;
- }
- }
-
- private function http_post($url,$param,$post_file=false){
- $oCurl = curl_init();
- if(stripos($url,"https://")!==FALSE){
- curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($oCurl, CURLOPT_SSLVERSION, 1);
- }
- if (is_string($param) || $post_file) {
- $strPOST = $param;
- } else {
- $aPOST = array();
- foreach($param as $key=>$val){
- $aPOST[] = $key."=".urlencode($val);
- }
- $strPOST = join("&", $aPOST);
- }
- curl_setopt($oCurl, CURLOPT_URL, $url);
- curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($oCurl, CURLOPT_POST,true);
- curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
- $sContent = curl_exec($oCurl);
- $aStatus = curl_getinfo($oCurl);
- curl_close($oCurl);
- if(intval($aStatus["http_code"])==200){
- return $sContent;
- }else{
- return false;
- }
- }
-
- protected function setCache($cachename,$value,$expired){
-
- return false;
- }
-
- protected function getCache($cachename){
-
- return false;
- }
-
- protected function removeCache($cachename){
-
- return false;
- }
-
- public function checkAuth($appid='',$appsecret='',$token=''){
- if (!$appid || !$appsecret) {
- $appid = $this->appid;
- $appsecret = $this->appsecret;
- }
- if ($token) {
- $this->access_token=$token;
- return $this->access_token;
- }
- $authname = 'wechat_access_token'.$appid;
- if ($rs = $this->getCache($authname)) {
- $this->access_token = $rs;
- return $rs;
- }
- $result = $this->http_get(self::API_URL_PREFIX.self::AUTH_URL.'appid='.$appid.'&secret='.$appsecret);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- $this->access_token = $json['access_token'];
- $expire = $json['expires_in'] ? intval($json['expires_in'])-100 : 3600;
- $this->setCache($authname,$this->access_token,$expire);
- return $this->access_token;
- }
- return false;
- }
-
- public function resetAuth($appid=''){
- if (!$appid) $appid = $this->appid;
- $this->access_token = '';
- $authname = 'wechat_access_token'.$appid;
- $this->removeCache($authname);
- return true;
- }
-
- public function resetJsTicket($appid=''){
- if (!$appid) $appid = $this->appid;
- $this->jsapi_ticket = '';
- $authname = 'wechat_jsapi_ticket'.$appid;
- $this->removeCache($authname);
- return true;
- }
-
- public function getJsTicket($appid='',$jsapi_ticket=''){
- if (!$this->access_token && !$this->checkAuth()) return false;
- if (!$appid) $appid = $this->appid;
- if ($jsapi_ticket) {
- $this->jsapi_ticket = $jsapi_ticket;
- return $this->jsapi_ticket;
- }
- $authname = 'wechat_jsapi_ticket'.$appid;
- if ($rs = $this->getCache($authname)) {
- $this->jsapi_ticket = $rs;
- return $rs;
- }
- $result = $this->http_get(self::API_URL_PREFIX.self::GET_TICKET_URL.'access_token='.$this->access_token.'&type=jsapi');
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- $this->jsapi_ticket = $json['ticket'];
- $expire = $json['expires_in'] ? intval($json['expires_in'])-100 : 3600;
- $this->setCache($authname,$this->jsapi_ticket,$expire);
- return $this->jsapi_ticket;
- }
- return false;
- }
-
- public function getJsSign($url, $timestamp=0, $noncestr='', $appid=''){
- if (!$this->jsapi_ticket && !$this->getJsTicket($appid) || !$url) return false;
- if (!$timestamp)
- $timestamp = time();
- if (!$noncestr)
- $noncestr = $this->generateNonceStr();
- $ret = strpos($url,'#');
- if ($ret)
- $url = substr($url,0,$ret);
- $url = trim($url);
- if (empty($url))
- return false;
- $arrdata = array("timestamp" => $timestamp, "noncestr" => $noncestr, "url" => $url, "jsapi_ticket" => $this->jsapi_ticket);
- $sign = $this->getSignature($arrdata);
- if (!$sign)
- return false;
- $signPackage = array(
- "appid" => $this->appid,
- "noncestr" => $noncestr,
- "timestamp" => $timestamp,
- "url" => $url,
- "signature" => $sign
- );
- return $signPackage;
- }
-
- static function json_encode($arr) {
- $parts = array ();
- $is_list = false;
-
- $keys = array_keys ( $arr );
- $max_length = count ( $arr ) - 1;
- if (($keys [0] === 0) && ($keys [$max_length] === $max_length )) {
- $is_list = true;
- for($i = 0; $i < count ( $keys ); $i ++) {
- if ($i != $keys [$i]) {
- $is_list = false;
- break;
- }
- }
- }
- foreach ( $arr as $key => $value ) {
- if (is_array ( $value )) {
- if ($is_list)
- $parts [] = self::json_encode ( $value );
- else
- $parts [] = '"' . $key . '":' . self::json_encode ( $value );
- } else {
- $str = '';
- if (! $is_list)
- $str = '"' . $key . '":';
-
- if (!is_string ( $value ) && is_numeric ( $value ) && $value<2000000000)
- $str .= $value;
- elseif ($value === false)
- $str .= 'false';
- elseif ($value === true)
- $str .= 'true';
- else
- $str .= '"' . addslashes ( $value ) . '"';
-
- $parts [] = $str;
- }
- }
- $json = implode ( ',', $parts );
- if ($is_list)
- return '[' . $json . ']';
- return '{' . $json . '}';
- }
-
- public function getSignature($arrdata,$method="sha1") {
- if (!function_exists($method)) return false;
- ksort($arrdata);
- $paramstring = "";
- foreach($arrdata as $key => $value)
- {
- if(strlen($paramstring) == 0)
- $paramstring .= $key . "=" . $value;
- else
- $paramstring .= "&" . $key . "=" . $value;
- }
- $Sign = $method($paramstring);
- return $Sign;
- }
-
- public function generateNonceStr($length=16){
-
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- $str = "";
- for($i = 0; $i < $length; $i++)
- {
- $str .= $chars[mt_rand(0, strlen($chars) - 1)];
- }
- return $str;
- }
-
- public function getServerIp(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::CALLBACKSERVER_GET_URL.'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json['ip_list'];
- }
- return false;
- }
-
- public function createMenu($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MENU_CREATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function getMenu(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::MENU_GET_URL.'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function deleteMenu(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::MENU_DELETE_URL.'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function uploadMedia($data, $type){
- if (!$this->access_token && !$this->checkAuth()) return false;
-
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_UPLOAD_URL.'access_token='.$this->access_token.'&type='.$type,$data,true);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getMedia($media_id,$is_video=false){
- if (!$this->access_token && !$this->checkAuth()) return false;
-
-
- $url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;
- $result = $this->http_get($url_prefix.self::MEDIA_GET_URL.'access_token='.$this->access_token.'&media_id='.$media_id);
- if ($result)
- {
- if (is_string($result)) {
- $json = json_decode($result,true);
- if (isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- }
- return $result;
- }
- return false;
- }
-
- public function uploadImg($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
-
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_UPLOADIMG_URL.'access_token='.$this->access_token,$data,true);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function uploadForeverMedia($data, $type,$is_video=false,$video_info=array()){
- if (!$this->access_token && !$this->checkAuth()) return false;
-
-
-
-
- if ($is_video) $data['description'] = self::json_encode($video_info);
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_UPLOAD_URL.'access_token='.$this->access_token.'&type='.$type,$data,true);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function uploadForeverArticles($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPLOAD_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateForeverArticles($media_id,$data,$index=0){
- if (!$this->access_token && !$this->checkAuth()) return false;
- if (!isset($data['media_id'])) $data['media_id'] = $media_id;
- if (!isset($data['index'])) $data['index'] = $index;
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getForeverMedia($media_id,$is_video=false){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array('media_id' => $media_id);
-
-
-
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_GET_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- if (is_string($result)) {
- $json = json_decode($result,true);
- if (isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return $result;
- }
- return false;
- }
-
- public function delForeverMedia($media_id){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array('media_id' => $media_id);
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_DEL_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function getForeverList($type,$offset,$count){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'type' => $type,
- 'offset' => $offset,
- 'count' => $count,
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_BATCHGET_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getForeverCount(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::MEDIA_FOREVER_COUNT_URL.'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function uploadArticles($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_UPLOADNEWS_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function uploadMpVideo($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::UPLOAD_MEDIA_URL.self::MEDIA_VIDEO_UPLOAD.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function sendMassMessage($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MASS_SEND_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function sendGroupMassMessage($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MASS_SEND_GROUP_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function deleteMassMessage($msg_id){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MASS_DELETE_URL.'access_token='.$this->access_token,self::json_encode(array('msg_id'=>$msg_id)));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function previewMassMessage($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MASS_PREVIEW_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function queryMassMessage($msg_id){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::MASS_QUERY_URL.'access_token='.$this->access_token,self::json_encode(array('msg_id'=>$msg_id)));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getQRCode($scene_id,$type=0,$expire=1800){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $type = ($type && is_string($scene_id))?2:$type;
- $data = array(
- 'action_name'=>$type?($type == 2?"QR_LIMIT_STR_SCENE":"QR_LIMIT_SCENE"):"QR_SCENE",
- 'expire_seconds'=>$expire,
- 'action_info'=>array('scene'=>($type == 2?array('scene_str'=>$scene_id):array('scene_id'=>$scene_id)))
- );
- if ($type == 1) {
- unset($data['expire_seconds']);
- }
- $result = $this->http_post(self::API_URL_PREFIX.self::QRCODE_CREATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getQRUrl($ticket) {
- return self::QRCODE_IMG_URL.urlencode($ticket);
- }
-
- public function getShortUrl($long_url){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'action'=>'long2short',
- 'long_url'=>$long_url
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::SHORT_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json['short_url'];
- }
- return false;
- }
-
- public function getDatacube($type,$subtype,$begin_date,$end_date=''){
- if (!$this->access_token && !$this->checkAuth()) return false;
- if (!isset(self::$DATACUBE_URL_ARR[$type]) || !isset(self::$DATACUBE_URL_ARR[$type][$subtype]))
- return false;
- $data = array(
- 'begin_date'=>$begin_date,
- 'end_date'=>$end_date?$end_date:$begin_date
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX.self::$DATACUBE_URL_ARR[$type][$subtype].'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return isset($json['list'])?$json['list']:$json;
- }
- return false;
- }
-
- public function getUserList($next_openid=''){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::USER_GET_URL.'access_token='.$this->access_token.'&next_openid='.$next_openid);
- if ($result)
- {
- $json = json_decode($result,true);
- if (isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getUserInfo($openid){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::USER_INFO_URL.'access_token='.$this->access_token.'&openid='.$openid);
- if ($result)
- {
- $json = json_decode($result,true);
- if (isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateUserRemark($openid,$remark){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'openid'=>$openid,
- 'remark'=>$remark
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::USER_UPDATEREMARK_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getGroup(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::GROUP_GET_URL.'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (isset($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getUserGroup($openid){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'openid'=>$openid
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::USER_GROUP_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- } else
- if (isset($json['groupid'])) return $json['groupid'];
- }
- return false;
- }
-
- public function createGroup($name){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'group'=>array('name'=>$name)
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::GROUP_CREATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateGroup($groupid,$name){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'group'=>array('id'=>$groupid,'name'=>$name)
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::GROUP_UPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateGroupMembers($groupid,$openid){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'openid'=>$openid,
- 'to_groupid'=>$groupid
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::GROUP_MEMBER_UPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function batchUpdateGroupMembers($groupid,$openid_list){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'openid_list'=>$openid_list,
- 'to_groupid'=>$groupid
- );
- $result = $this->http_post(self::API_URL_PREFIX.self::GROUP_MEMBER_BATCHUPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function sendCustomMessage($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::CUSTOM_SEND_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getOauthRedirect($callback,$state='',$scope='snsapi_userinfo'){
- return self::OAUTH_PREFIX.self::OAUTH_AUTHORIZE_URL.'appid='.$this->appid.'&redirect_uri='.urlencode($callback).'&response_type=code&scope='.$scope.'&state='.$state.'#wechat_redirect';
- }
-
- public function getOauthAccessToken(){
- $code = isset($_GET['code'])?$_GET['code']:'';
- if (!$code) return false;
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::OAUTH_TOKEN_URL.'appid='.$this->appid.'&secret='.$this->appsecret.'&code='.$code.'&grant_type=authorization_code');
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- $this->user_token = $json['access_token'];
- return $json;
- }
- return false;
- }
-
- public function getOauthRefreshToken($refresh_token){
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::OAUTH_REFRESH_URL.'appid='.$this->appid.'&grant_type=refresh_token&refresh_token='.$refresh_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- $this->user_token = $json['access_token'];
- return $json;
- }
- return false;
- }
-
- public function getOauthUserinfo($access_token,$openid){
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::OAUTH_USERINFO_URL.'access_token='.$access_token.'&openid='.$openid);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getOauthAuth($access_token,$openid){
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::OAUTH_AUTH_URL.'access_token='.$access_token.'&openid='.$openid);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- } else
- if ($json['errcode']==0) return true;
- }
- return false;
- }
-
- public function setTMIndustry($id1,$id2=''){
- if ($id1) $data['industry_id1'] = $id1;
- if ($id2) $data['industry_id2'] = $id2;
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::TEMPLATE_SET_INDUSTRY_URL.'access_token='.$this->access_token,self::json_encode($data));
- if($result){
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function addTemplateMessage($tpl_id){
- $data = array ('template_id_short' =>$tpl_id);
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::TEMPLATE_ADD_TPL_URL.'access_token='.$this->access_token,self::json_encode($data));
- if($result){
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json['template_id'];
- }
- return false;
- }
-
- public function sendTemplateMessage($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::TEMPLATE_SEND_URL.'access_token='.$this->access_token,self::json_encode($data));
- if($result){
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getCustomServiceMessage($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::CUSTOM_SERVICE_GET_RECORD.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function transfer_customer_service($customer_account = '')
- {
- $msg = array(
- 'ToUserName' => $this->getRevFrom(),
- 'FromUserName'=>$this->getRevTo(),
- 'CreateTime'=>time(),
- 'MsgType'=>'transfer_customer_service',
- );
- if ($customer_account) {
- $msg['TransInfo'] = array('KfAccount'=>$customer_account);
- }
- $this->Message($msg);
- return $this;
- }
-
- public function getCustomServiceKFlist(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::CUSTOM_SERVICE_GET_KFLIST.'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getCustomServiceOnlineKFlist(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_URL_PREFIX.self::CUSTOM_SERVICE_GET_ONLINEKFLIST.'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function createKFSession($openid,$kf_account,$text=''){
- $data=array(
- "openid" =>$openid,
- "kf_account" => $kf_account
- );
- if ($text) $data["text"] = $text;
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX.self::CUSTOM_SESSION_CREATE.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function closeKFSession($openid,$kf_account,$text=''){
- $data=array(
- "openid" =>$openid,
- "kf_account" => $kf_account
- );
- if ($text) $data["text"] = $text;
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX.self::CUSTOM_SESSION_CLOSE .'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getKFSession($openid){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::CUSTOM_SESSION_GET .'access_token='.$this->access_token.'&openid='.$openid);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getKFSessionlist($kf_account){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::CUSTOM_SESSION_GET_LIST .'access_token='.$this->access_token.'&kf_account='.$kf_account);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getKFSessionWait(){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::CUSTOM_SESSION_GET_WAIT .'access_token='.$this->access_token);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function addKFAccount($account,$nickname,$password){
- $data=array(
- "kf_account" =>$account,
- "nickname" => $nickname,
- "password" => md5($password)
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX.self::CS_KF_ACCOUNT_ADD_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateKFAccount($account,$nickname,$password){
- $data=array(
- "kf_account" =>$account,
- "nickname" => $nickname,
- "password" => md5($password)
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX.self::CS_KF_ACCOUNT_UPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function deleteKFAccount($account){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_BASE_URL_PREFIX.self::CS_KF_ACCOUNT_DEL_URL.'access_token='.$this->access_token.'&kf_account='.$account);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function setKFHeadImg($account,$imgfile){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX.self::CS_KF_ACCOUNT_UPLOAD_HEADIMG_URL.'access_token='.$this->access_token.'&kf_account='.$account,array('media'=>'@'.$imgfile),true);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function querySemantic($uid,$query,$category,$latitude=0,$longitude=0,$city="",$region=""){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data=array(
- 'query' => $query,
- 'category' => $category,
- 'appid' => $this->appid,
- 'uid' => ''
- );
-
- if ($latitude) {
- $data['latitude'] = $latitude;
- $data['longitude'] = $longitude;
- } elseif ($city) {
- $data['city'] = $city;
- } elseif ($region) {
- $data['region'] = $region;
- }
- $result = $this->http_post(self::API_BASE_URL_PREFIX.self::SEMANTIC_API_URL.'access_token='.$this->access_token,self::json_encode($data));
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function createCard($data) {
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_CREATE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateCard($data) {
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_UPDATE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function delCard($card_id) {
- $data = array(
- 'card_id' => $card_id,
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_DELETE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function getCardInfo($card_id) {
- $data = array(
- 'card_id' => $card_id,
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_GET . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getCardColors() {
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_get(self::API_BASE_URL_PREFIX . self::CARD_GETCOLORS . 'access_token=' . $this->access_token);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getCardLocations($offset=0,$count=0) {
- $data=array(
- 'offset'=>$offset,
- 'count'=>$count
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_LOCATION_BATCHGET . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function addCardLocations($data) {
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_LOCATION_BATCHADD . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function createCardQrcode($card_id,$code='',$openid='',$expire_seconds=0,$is_unique_code=false,$balance='') {
- $card = array(
- 'card_id' => $card_id
- );
- if ($code)
- $card['code'] = $code;
- if ($openid)
- $card['openid'] = $openid;
- if ($expire_seconds)
- $card['expire_seconds'] = $expire_seconds;
- if ($is_unique_code)
- $card['is_unique_code'] = $is_unique_code;
- if ($balance)
- $card['balance'] = $balance;
- $data = array(
- 'action_name' => "QR_CARD",
- 'action_info' => array('card' => $card)
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_QRCODE_CREATE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function consumeCardCode($code,$card_id='') {
- $data = array('code' => $code);
- if ($card_id)
- $data['card_id'] = $card_id;
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_CODE_CONSUME . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function decryptCardCode($encrypt_code) {
- $data = array(
- 'encrypt_code' => $encrypt_code,
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_CODE_DECRYPT . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function checkCardCode($code) {
- $data = array(
- 'code' => $code,
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_CODE_GET . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getCardIdList($offset=0,$count=50) {
- if ($count>50)
- $count = 50;
- $data = array(
- 'offset' => $offset,
- 'count' => $count,
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_BATCHGET . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateCardCode($code,$card_id,$new_code) {
- $data = array(
- 'code' => $code,
- 'card_id' => $card_id,
- 'new_code' => $new_code,
- );
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_CODE_UPDATE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function unavailableCardCode($code,$card_id='') {
- $data = array(
- 'code' => $code,
- );
- if ($card_id)
- $data['card_id'] = $card_id;
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_CODE_UNAVAILABLE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function modifyCardStock($data) {
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_MODIFY_STOCK . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function activateMemberCard($data) {
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_MEMBERCARD_ACTIVATE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function updateMemberCard($data) {
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_MEMBERCARD_UPDATEUSER . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateLuckyMoney($code,$balance,$card_id='') {
- $data = array(
- 'code' => $code,
- 'balance' => $balance
- );
- if ($card_id)
- $data['card_id'] = $card_id;
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_LUCKYMONEY_UPDATE . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function setCardTestWhiteList($openid=array(),$user=array()) {
- $data = array();
- if (count($openid) > 0)
- $data['openid'] = $openid;
- if (count($user) > 0)
- $data['username'] = $user;
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::CARD_TESTWHILELIST_SET . 'access_token=' . $this->access_token, self::json_encode($data));
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function applyShakeAroundDevice($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_DEVICE_APPLYID . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateShakeAroundDevice($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_DEVICE_UPDATE . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function searchShakeAroundDevice($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_DEVICE_SEARCH . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function bindLocationShakeAroundDevice($device_id,$poi_id,$uuid='',$major=0,$minor=0){
- if (!$this->access_token && !$this->checkAuth()) return false;
- if(!$device_id){
- if(!$uuid || !$major || !$minor){
- return false;
- }
- $device_identifier = array(
- 'uuid' => $uuid,
- 'major' => $major,
- 'minor' => $minor
- );
- }else{
- $device_identifier = array(
- 'device_id' => $device_id
- );
- }
- $data = array(
- 'device_identifier' => $device_identifier,
- 'poi_id' => $poi_id
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_DEVICE_BINDLOCATION . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function bindPageShakeAroundDevice($device_id,$page_ids=array(),$bind=1,$append=1,$uuid='',$major=0,$minor=0){
- if (!$this->access_token && !$this->checkAuth()) return false;
- if(!$device_id){
- if(!$uuid || !$major || !$minor){
- return false;
- }
- $device_identifier = array(
- 'uuid' => $uuid,
- 'major' => $major,
- 'minor' => $minor
- );
- }else{
- $device_identifier = array(
- 'device_id' => $device_id
- );
- }
- $data = array(
- 'device_identifier' => $device_identifier,
- 'page_ids' => $page_ids,
- 'bind' => $bind,
- 'append' => $append
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_DEVICE_BINDPAGE . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function uploadShakeAroundMedia($data){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $result = $this->http_post(self::API_URL_PREFIX.self::SHAKEAROUND_MATERIAL_ADD.'access_token='.$this->access_token,$data,true);
- if ($result)
- {
- $json = json_decode($result,true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function addShakeAroundPage($title,$description,$icon_url,$page_url,$comment=''){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- "title" => $title,
- "description" => $description,
- "icon_url" => $icon_url,
- "page_url" => $page_url,
- "comment" => $comment
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_PAGE_ADD . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function updateShakeAroundPage($page_id,$title,$description,$icon_url,$page_url,$comment=''){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- "page_id" => $page_id,
- "title" => $title,
- "description" => $description,
- "icon_url" => $icon_url,
- "page_url" => $page_url,
- "comment" => $comment
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_PAGE_UPDATE . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function searchShakeAroundPage($page_ids=array(),$begin=0,$count=1){
- if (!$this->access_token && !$this->checkAuth()) return false;
- if(!empty($page_ids)){
- $data = array(
- 'page_ids' => $page_ids
- );
- }else{
- $data = array(
- 'begin' => $begin,
- 'count' => $count
- );
- }
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_PAGE_SEARCH . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function deleteShakeAroundPage($page_ids=array()){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'page_ids' => $page_ids
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_PAGE_DELETE . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function getShakeInfoShakeAroundUser($ticket){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array('ticket' => $ticket);
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_USER_GETSHAKEINFO . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function deviceShakeAroundStatistics($device_id,$begin_date,$end_date,$uuid='',$major=0,$minor=0){
- if (!$this->access_token && !$this->checkAuth()) return false;
- if(!$device_id){
- if(!$uuid || !$major || !$minor){
- return false;
- }
- $device_identifier = array(
- 'uuid' => $uuid,
- 'major' => $major,
- 'minor' => $minor
- );
- }else{
- $device_identifier = array(
- 'device_id' => $device_id
- );
- }
- $data = array(
- 'device_identifier' => $device_identifier,
- 'begin_date' => $begin_date,
- 'end_date' => $end_date
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_STATISTICS_DEVICE . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
-
- public function pageShakeAroundStatistics($page_id,$begin_date,$end_date){
- if (!$this->access_token && !$this->checkAuth()) return false;
- $data = array(
- 'page_id' => $page_id,
- 'begin_date' => $begin_date,
- 'end_date' => $end_date
- );
- $result = $this->http_post(self::API_BASE_URL_PREFIX . self::SHAKEAROUND_STATISTICS_DEVICE . 'access_token=' . $this->access_token, self::json_encode($data));
- $this->log($result);
- if ($result) {
- $json = json_decode($result, true);
- if (!$json || !empty($json['errcode'])) {
- $this->errCode = $json['errcode'];
- $this->errMsg = $json['errmsg'];
- return false;
- }
- return $json;
- }
- return false;
- }
- }
- class PKCS7Encoder
- {
- public static $block_size = 32;
-
- function encode($text)
- {
- $block_size = PKCS7Encoder::$block_size;
- $text_length = strlen($text);
-
- $amount_to_pad = PKCS7Encoder::$block_size - ($text_length % PKCS7Encoder::$block_size);
- if ($amount_to_pad == 0) {
- $amount_to_pad = PKCS7Encoder::block_size;
- }
-
- $pad_chr = chr($amount_to_pad);
- $tmp = "";
- for ($index = 0; $index < $amount_to_pad; $index++) {
- $tmp .= $pad_chr;
- }
- return $text . $tmp;
- }
-
- function decode($text)
- {
- $pad = ord(substr($text, -1));
- if ($pad < 1 || $pad > PKCS7Encoder::$block_size) {
- $pad = 0;
- }
- return substr($text, 0, (strlen($text) - $pad));
- }
- }
- class Prpcrypt
- {
- public $key;
- function __construct($k) {
- $this->key = base64_decode($k . "=");
- }
-
- function Prpcrypt($k)
- {
- $this->key = base64_decode($k . "=");
- }
-
- public function encrypt($text, $appid)
- {
- try {
-
- $random = $this->getRandomStr();
- $text = $random . pack("N", strlen($text)) . $text . $appid;
-
- $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
- $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
- $iv = substr($this->key, 0, 16);
-
- $pkc_encoder = new PKCS7Encoder;
- $text = $pkc_encoder->encode($text);
- mcrypt_generic_init($module, $this->key, $iv);
-
- $encrypted = mcrypt_generic($module, $text);
- mcrypt_generic_deinit($module);
- mcrypt_module_close($module);
-
-
- return array(ErrorCode::$OK, base64_encode($encrypted));
- } catch (Exception $e) {
-
- return array(ErrorCode::$EncryptAESError, null);
- }
- }
-
- public function decrypt($encrypted, $appid)
- {
- try {
-
- $ciphertext_dec = base64_decode($encrypted);
- $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
- $iv = substr($this->key, 0, 16);
- mcrypt_generic_init($module, $this->key, $iv);
-
- $decrypted = mdecrypt_generic($module, $ciphertext_dec);
- mcrypt_generic_deinit($module);
- mcrypt_module_close($module);
- } catch (Exception $e) {
- return array(ErrorCode::$DecryptAESError, null);
- }
- try {
-
- $pkc_encoder = new PKCS7Encoder;
- $result = $pkc_encoder->decode($decrypted);
-
- if (strlen($result) < 16)
- return "";
- $content = substr($result, 16, strlen($result));
- $len_list = unpack("N", substr($content, 0, 4));
- $xml_len = $len_list[1];
- $xml_content = substr($content, 4, $xml_len);
- $from_appid = substr($content, $xml_len + 4);
- if (!$appid)
- $appid = $from_appid;
-
- } catch (Exception $e) {
-
- return array(ErrorCode::$IllegalBuffer, null);
- }
- if ($from_appid != $appid)
- return array(ErrorCode::$ValidateAppidError, null);
-
- return array(0, $xml_content, $from_appid);
- }
-
- function getRandomStr()
- {
- $str = "";
- $str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
- $max = strlen($str_pol) - 1;
- for ($i = 0; $i < 16; $i++) {
- $str .= $str_pol[mt_rand(0, $max)];
- }
- return $str;
- }
- }
- class ErrorCode
- {
- public static $OK = 0;
- public static $ValidateSignatureError = 40001;
- public static $ParseXmlError = 40002;
- public static $ComputeSignatureError = 40003;
- public static $IllegalAesKey = 40004;
- public static $ValidateAppidError = 40005;
- public static $EncryptAESError = 40006;
- public static $DecryptAESError = 40007;
- public static $IllegalBuffer = 40008;
- public static $EncodeBase64Error = 40009;
- public static $DecodeBase64Error = 40010;
- public static $GenReturnXmlError = 40011;
- public static $errCode=array(
- '0' => '处理成功',
- '40001' => '校验签名失败',
- '40002' => '解析xml失败',
- '40003' => '计算签名失败',
- '40004' => '不合法的AESKey',
- '40005' => '校验AppID失败',
- '40006' => 'AES加密失败',
- '40007' => 'AES解密失败',
- '40008' => '公众平台发送的xml不合法',
- '40009' => 'Base64编码失败',
- '40010' => 'Base64解码失败',
- '40011' => '公众帐号生成回包xml失败'
- );
- public static function getErrText($err) {
- if (isset(self::$errCode[$err])) {
- return self::$errCode[$err];
- }else {
- return false;
- };
- }
- }
|