wecom.cjs 191 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688
  1. 'use strict';
  2. const win = typeof window !== 'undefined' ? window : undefined;
  3. const doc = typeof document !== 'undefined' ? document : undefined;
  4. const nav = typeof navigator !== 'undefined' ? navigator : undefined;
  5. const loc = typeof location !== 'undefined' ? location : undefined;
  6. function getHref() {
  7. return loc?.href || '';
  8. }
  9. function getTitle() {
  10. return doc?.title || '';
  11. }
  12. const ua = nav?.userAgent || '';
  13. const platform = nav?.platform || '';
  14. const wecomVersion = ua?.match(/wxwork\/([\d.]+)/i)?.[1];
  15. const isWeCom = !!wecomVersion;
  16. const isWeChat = !isWeCom && /micromessenger/i.test(ua);
  17. const isAndroid = /\bAndroid\b/i.test(ua);
  18. const isWindows = /Win/i.test(platform);
  19. const { isIOS, isMac } = getAppleDeviceType();
  20. function getAppleDeviceType() {
  21. const maxTouchPoints = nav?.maxTouchPoints ?? 1;
  22. const isMac = /Mac/i.test(platform);
  23. // https://stackoverflow.com/questions/56934826/distinguish-between-ipad-and-mac-on-ipad-with-ipados
  24. if (isMac && maxTouchPoints > 2) {
  25. return {
  26. isMac: false,
  27. isIOS: true
  28. };
  29. }
  30. return {
  31. isMac,
  32. isIOS: /\b(iPhone|iPad|iPod)\b/i.test(ua)
  33. };
  34. }
  35. let registerOptions;
  36. let corpConfigTask;
  37. let agentConfigTask;
  38. function setRegisterOptions(options) {
  39. if (!options.corpId) {
  40. throw new Error('Missing corpId');
  41. }
  42. registerOptions = options;
  43. }
  44. function getRegisterOptions() {
  45. return registerOptions;
  46. }
  47. function getCorpConfigTask() {
  48. return corpConfigTask;
  49. }
  50. function setCorpConfigTask(task) {
  51. corpConfigTask = task;
  52. }
  53. function getCorpConfigParams() {
  54. return corpConfigTask?.getResult()?.params;
  55. }
  56. function getAgentConfigTask() {
  57. return agentConfigTask;
  58. }
  59. function setAgentConfigTask(task) {
  60. agentConfigTask = task;
  61. }
  62. function getAgentConfigParams() {
  63. return agentConfigTask?.getResult()?.params;
  64. }
  65. function getConfigParams() {
  66. const registerOptions = getRegisterOptions();
  67. if (isWeCom && registerOptions?.getAgentConfigSignature) {
  68. return getAgentConfigParams();
  69. }
  70. return getCorpConfigParams();
  71. }
  72. function getConfigCorpId() {
  73. const registerOptions = getRegisterOptions();
  74. if (isWeCom && registerOptions?.getAgentConfigSignature) {
  75. const params = getAgentConfigParams();
  76. return params?.corpid;
  77. }
  78. const params = getCorpConfigParams();
  79. return params?.appId;
  80. }
  81. /**
  82. * 获取 config 或 agentConfig 传入的相关参数
  83. *
  84. * 用于外部 sdk 调用私有方法
  85. */ function getVerifyParams() {
  86. const verifyParams = getConfigParams();
  87. if (!verifyParams) {
  88. return;
  89. }
  90. const corpId = getConfigCorpId();
  91. return {
  92. appId: corpId,
  93. verifyAppId: corpId,
  94. verifySignType: 'sha1',
  95. verifyTimestamp: verifyParams.timestamp,
  96. verifyNonceStr: verifyParams.nonceStr,
  97. verifySignature: verifyParams.signature
  98. };
  99. }
  100. const webToClientJsApiMap = {
  101. config: 'preVerifyJsApi',
  102. onMenuShareTimeline: 'menu:share:timeline',
  103. onMenuShareAppMessage: 'menu:share:appmessage',
  104. onMenuShareWechat: 'menu:share:wechat',
  105. onMenuShareQQ: 'menu:share:qq',
  106. onMenuShareWeibo: 'menu:share:weiboApp',
  107. onMenuShareQZone: 'menu:share:QZone',
  108. previewImage: 'imagePreview',
  109. getLocation: 'geoLocation',
  110. openProductSpecificView: 'openProductViewWithPid',
  111. addCard: 'batchAddCard',
  112. openCard: 'batchViewCard',
  113. chooseWXPay: 'getBrandWCPayRequest',
  114. openEnterpriseRedPacket: 'getRecevieBizHongBaoRequest',
  115. startSearchBeacons: 'startMonitoringBeacons',
  116. stopSearchBeacons: 'stopMonitoringBeacons',
  117. onSearchBeacons: 'onBeaconsInRange',
  118. consumeAndShareCard: 'consumedShareCard',
  119. openAddress: 'editAddress',
  120. getBrandWCPayRequest: 'getBrandWCPayRequest'
  121. };
  122. const clientToWebJsApiMap = {};
  123. for (const key of Object.keys(webToClientJsApiMap)){
  124. clientToWebJsApiMap[webToClientJsApiMap[key]] = key;
  125. }
  126. function mapJsApiNameToClient(name) {
  127. return webToClientJsApiMap[name] || name;
  128. }
  129. function mapJsApiNameToWeb(name) {
  130. return clientToWebJsApiMap[name] || name;
  131. }
  132. function mapJsApiListToClient(list) {
  133. return list.map(mapJsApiNameToClient);
  134. }
  135. function error(...args) {
  136. console.error('[wwsdk]', ...args);
  137. }
  138. const originalHref = getHref();
  139. /**
  140. * 两个 SemVer 相减,取差的符号
  141. */ function semverSubtract(v1, v2) {
  142. const v1Seg = v1?.split('.') || [];
  143. const v2Seg = v2?.split('.') || [];
  144. for(let i = 0, ii = Math.max(v1Seg.length, v2Seg.length); i < ii; i++){
  145. const v1Num = parseInt(v1Seg[i]) || 0;
  146. const v2Num = parseInt(v2Seg[i]) || 0;
  147. if (v1Num > v2Num) {
  148. return 1;
  149. }
  150. if (v1Num < v2Num) {
  151. return -1;
  152. }
  153. }
  154. return 0;
  155. }
  156. function arrayBufferToBase64(buffer) {
  157. if (typeof Buffer !== 'undefined') {
  158. return Buffer.from(buffer).toString('base64');
  159. }
  160. let binary = '';
  161. const bytes = new Uint8Array(buffer);
  162. const len = bytes.byteLength;
  163. for(let i = 0; i < len; i++){
  164. binary += String.fromCharCode(bytes[i]);
  165. }
  166. return btoa(binary);
  167. }
  168. function base64ToArrayBuffer(base64) {
  169. if (typeof Buffer !== 'undefined') {
  170. return Buffer.from(base64, 'base64').buffer;
  171. }
  172. const binary = atob(base64);
  173. const length = binary.length;
  174. const bytes = new Uint8Array(length);
  175. for(let i = 0; i < length; i++){
  176. bytes[i] = binary.charCodeAt(i);
  177. }
  178. return bytes.buffer;
  179. }
  180. function safeRun(fn, param, thisArg) {
  181. if (!isFunction(fn)) {
  182. return;
  183. }
  184. try {
  185. return fn.call(thisArg, param);
  186. } catch (error$1) {
  187. error(error$1);
  188. }
  189. }
  190. function startsWith(str, search) {
  191. return str.slice(0, search.length) === search;
  192. }
  193. function getSignURL(original) {
  194. if (original) {
  195. return originalHref.split('#')[0];
  196. }
  197. return getHref().split('#')[0];
  198. }
  199. function extractErrMsgKeyword(errMsg) {
  200. if (!isString(errMsg)) {
  201. return '';
  202. }
  203. return errMsg.slice(errMsg.indexOf(':') + 1);
  204. }
  205. function isFalsy(val) {
  206. return val === false || val === 0;
  207. }
  208. function isObject$1(val) {
  209. if (!val) {
  210. return false;
  211. }
  212. return typeof val === 'object';
  213. }
  214. function isFunction(val) {
  215. return typeof val === 'function';
  216. }
  217. function isString(val) {
  218. return typeof val === 'string';
  219. }
  220. function joinList(list) {
  221. if (!list) {
  222. return list;
  223. }
  224. if (isString(list)) {
  225. return list;
  226. }
  227. return list.join(';');
  228. }
  229. /**
  230. * WeixinJSBridge 是否已注入到 window
  231. */ exports.isWeixinJSBridgeReady = !!win?.WeixinJSBridge;
  232. /**
  233. * 等待 WeixinJSBridge 注入到 window
  234. */ exports.onWeixinJSBridgeReady = Promise.resolve();
  235. if (!exports.isWeixinJSBridgeReady) {
  236. exports.onWeixinJSBridgeReady = new Promise((resolve)=>{
  237. doc?.addEventListener('WeixinJSBridgeReady', ()=>{
  238. exports.isWeixinJSBridgeReady = true;
  239. resolve();
  240. });
  241. });
  242. }
  243. /**
  244. * 监听 JSSDK 未定义的事件
  245. *
  246. * @example
  247. * ```ts
  248. * ww.on('onBeaconsInRange', res => {
  249. * console.log(res)
  250. * })
  251. * ```
  252. *
  253. * @param name 事件名称
  254. * @param callback 监听回调
  255. */ async function on(name, callback) {
  256. if (!exports.isWeixinJSBridgeReady) {
  257. await exports.onWeixinJSBridgeReady;
  258. }
  259. win.WeixinJSBridge.on(name, callback);
  260. }
  261. /**
  262. * 调用 JSSDK 未定义的 JSAPI
  263. *
  264. * @example
  265. * ```ts
  266. * ww.invoke('openEnterpriseChat', params, res => {
  267. * console.log(res)
  268. * })
  269. * ```
  270. *
  271. * @param name JSAPI 名称
  272. * @param params JSAPI 参数
  273. * @param callback 回调函数
  274. * @returns JSAPI 返回值
  275. */ async function invoke(name, params = {}, callback) {
  276. if (!exports.isWeixinJSBridgeReady) {
  277. await exports.onWeixinJSBridgeReady;
  278. }
  279. const result = await new Promise((resolve)=>{
  280. const fullParams = {
  281. ...params,
  282. ...getVerifyParams()
  283. };
  284. win.WeixinJSBridge.invoke(name, fullParams, resolve);
  285. });
  286. if (!result.errMsg) {
  287. result.errMsg = formatErrMsg(name, result.err_msg || result.errmsg);
  288. }
  289. const keyword = extractErrMsgKeyword(result.errMsg);
  290. if (result.errCode == null) {
  291. if (result.err_code != null) {
  292. result.errCode = result.err_code;
  293. } else {
  294. result.errCode = keyword === 'ok' ? 0 : -1;
  295. }
  296. }
  297. safeRun(callback, result);
  298. if (keyword !== 'ok' && keyword !== 'yes') {
  299. throw result;
  300. }
  301. return result;
  302. }
  303. function formatErrMsg(name, errMsg) {
  304. const apiName = mapJsApiNameToWeb(name);
  305. if (!errMsg) {
  306. return `${apiName}:ok`;
  307. }
  308. let keyword = extractErrMsgKeyword(errMsg);
  309. if (keyword === 'confirm') {
  310. keyword = 'ok';
  311. }
  312. if (keyword === 'failed') {
  313. keyword = 'fail';
  314. }
  315. if (startsWith(keyword, 'failed_')) {
  316. keyword = keyword.slice(7);
  317. }
  318. if (startsWith(keyword, 'fail_')) {
  319. keyword = keyword.slice(5);
  320. }
  321. keyword = keyword.replace(/_/g, '').toLowerCase();
  322. if (keyword === 'access denied' || keyword === 'no permission to execute') {
  323. keyword = 'permission denied';
  324. }
  325. if (apiName === 'config' && keyword === 'function not exist') {
  326. keyword = 'ok';
  327. }
  328. if (!keyword) {
  329. keyword = 'fail';
  330. }
  331. return `${apiName}:${keyword}`;
  332. }
  333. class SDKError extends Error {
  334. constructor(message){
  335. super(`SDK Error: ${message}`);
  336. }
  337. }
  338. class AbortError extends SDKError {
  339. constructor(){
  340. super('Aborted');
  341. }
  342. }
  343. function _define_property(obj, key, value) {
  344. if (key in obj) {
  345. Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
  346. } else obj[key] = value;
  347. return obj;
  348. }
  349. const CONFIG_TYPE_CORP = 1;
  350. const CONFIG_TYPE_AGENT = 2;
  351. class ConfigTask {
  352. checkValid() {
  353. if (isWeCom && this.url !== getSignURL(this.useOriginalURL)) {
  354. this.error = new AbortError();
  355. }
  356. return !this.error;
  357. }
  358. getResult() {
  359. if (this.checkValid()) {
  360. return this.result;
  361. }
  362. }
  363. async awaitPromise(promise) {
  364. try {
  365. this.result = await promise;
  366. return this.result;
  367. } catch (error) {
  368. this.error = error;
  369. throw error;
  370. }
  371. }
  372. constructor(type, factory){
  373. _define_property(this, "type", void 0);
  374. _define_property(this, "url", void 0);
  375. _define_property(this, "promise", void 0);
  376. _define_property(this, "result", void 0);
  377. _define_property(this, "error", void 0);
  378. _define_property(this, "useOriginalURL", void 0);
  379. this.type = type;
  380. this.useOriginalURL = isWeChat && !isWindows && !isMac && type === CONFIG_TYPE_CORP;
  381. this.url = getSignURL(this.useOriginalURL);
  382. this.promise = this.awaitPromise(factory(this.url));
  383. }
  384. }
  385. /**
  386. * 触发或等待 config 返回
  387. */ async function ensureCorpConfigReady() {
  388. const originalTask = getCorpConfigTask();
  389. if (originalTask?.checkValid()) {
  390. return originalTask.promise;
  391. }
  392. const task = new ConfigTask(CONFIG_TYPE_CORP, async (url)=>{
  393. const registerOptions = getRegisterOptions();
  394. if (!registerOptions?.getConfigSignature) {
  395. throw new SDKError('Missing getConfigSignature');
  396. }
  397. // 1. 获取 config 签名参数
  398. const data = await registerOptions.getConfigSignature(url);
  399. if (!task.checkValid()) {
  400. throw new AbortError();
  401. }
  402. // 2. 构建参数
  403. const params = buildCorpConfigParams(registerOptions, data);
  404. // 3. 调用 JSAPI
  405. const result = await invoke('preVerifyJSAPI', {
  406. appId: params.appId,
  407. verifyJsApiList: params.jsApiList,
  408. verifyOpenTagList: params.openTagList,
  409. verifyAppId: params.appId,
  410. verifySignType: 'sha1',
  411. verifyTimestamp: params.timestamp,
  412. verifyNonceStr: params.nonceStr,
  413. verifySignature: params.signature
  414. });
  415. if (!task.checkValid()) {
  416. throw new AbortError();
  417. }
  418. return {
  419. params,
  420. result
  421. };
  422. });
  423. task.promise.then((res)=>{
  424. const registerOptions = getRegisterOptions();
  425. safeRun(registerOptions?.onConfigSuccess, res.result);
  426. safeRun(registerOptions?.onConfigComplete, res.result);
  427. }, (error)=>{
  428. const registerOptions = getRegisterOptions();
  429. safeRun(registerOptions?.onConfigFail, error);
  430. safeRun(registerOptions?.onConfigComplete, error);
  431. });
  432. setCorpConfigTask(task);
  433. return task.promise;
  434. }
  435. function buildCorpConfigParams(options, data) {
  436. return {
  437. appId: options.corpId,
  438. timestamp: `${data.timestamp}`,
  439. nonceStr: data.nonceStr,
  440. signature: data.signature,
  441. jsApiList: mapJsApiListToClient(options.jsApiList || [
  442. 'config'
  443. ]),
  444. openTagList: mapJsApiListToClient(options.openTagList || [])
  445. };
  446. }
  447. /**
  448. * 触发或等待 agentConfig 返回
  449. */ async function ensureAgentConfigReady() {
  450. const originalTask = getAgentConfigTask();
  451. if (originalTask?.checkValid()) {
  452. return originalTask.promise;
  453. }
  454. const task = new ConfigTask(CONFIG_TYPE_AGENT, async (url)=>{
  455. // 1. 若为低版本企业微信,agentConfig 需要在 config 成功后执行
  456. let configPromise;
  457. if (isWeCom && semverSubtract(wecomVersion, '3.0.24') < 0) {
  458. configPromise = ensureCorpConfigReady();
  459. }
  460. // 2. 等待 config 成功的时候同时获取 agentConfig 签名参数
  461. const [params] = await Promise.all([
  462. resolveAgentConfigParams(url),
  463. configPromise
  464. ]);
  465. if (!task.checkValid()) {
  466. throw new AbortError();
  467. }
  468. // 4. 调用 JSAPI
  469. const result = await invoke('agentConfig', params);
  470. if (!task.checkValid()) {
  471. throw new AbortError();
  472. }
  473. return {
  474. params,
  475. result
  476. };
  477. });
  478. task.promise.then((res)=>handleAgentConfigSuccess(res.result), (error)=>handleAgentConfigFail(error));
  479. setAgentConfigTask(task);
  480. return task.promise;
  481. }
  482. async function resolveAgentConfigParams(url) {
  483. const registerOptions = getRegisterOptions();
  484. if (!registerOptions?.getAgentConfigSignature) {
  485. throw new SDKError('Missing getAgentConfigSignature');
  486. }
  487. const data = await registerOptions.getAgentConfigSignature(url);
  488. return {
  489. corpid: registerOptions.corpId,
  490. agentid: `${registerOptions.agentId}`,
  491. timestamp: `${data.timestamp}`,
  492. nonceStr: data.nonceStr,
  493. signature: data.signature,
  494. jsApiList: mapJsApiListToClient(registerOptions.jsApiList || [
  495. 'agentConfig'
  496. ])
  497. };
  498. }
  499. function handleAgentConfigSuccess(result) {
  500. const registerOptions = getRegisterOptions();
  501. safeRun(registerOptions?.onAgentConfigSuccess, result);
  502. safeRun(registerOptions?.onAgentConfigComplete, result);
  503. }
  504. function handleAgentConfigFail(error) {
  505. const registerOptions = getRegisterOptions();
  506. safeRun(registerOptions?.onAgentConfigFail, error);
  507. safeRun(registerOptions?.onAgentConfigComplete, error);
  508. }
  509. /**
  510. * 触发或等待 config、agentConfig 完成
  511. *
  512. * @example
  513. * ```ts
  514. * await ww.ensureConfigReady()
  515. * ```
  516. */ function ensureConfigReady() {
  517. const registerOptions = getRegisterOptions();
  518. if (isWeCom && registerOptions?.getAgentConfigSignature) {
  519. return ensureAgentConfigReady();
  520. }
  521. return ensureCorpConfigReady();
  522. }
  523. /**
  524. * 在提供了 registerOptions 的情况下保证 config、agentConfig 完成
  525. *
  526. * @private
  527. */ function tryEnsureConfigReady() {
  528. const registerOptions = getRegisterOptions();
  529. if (!registerOptions) {
  530. return;
  531. }
  532. if (isWeCom && registerOptions.getAgentConfigSignature) {
  533. return ensureAgentConfigReady();
  534. }
  535. if (registerOptions.getConfigSignature) {
  536. return ensureCorpConfigReady();
  537. }
  538. }
  539. /**
  540. * 注册应用信息。
  541. *
  542. * @example
  543. * ```ts
  544. * ww.register({
  545. * corpId: 'ww7ca4776b2a70000',
  546. * jsApiList: ['getExternalContact'],
  547. * getConfigSignature
  548. * })
  549. * ```
  550. */ function register(options) {
  551. setRegisterOptions(options);
  552. if (isWeChat || isWeCom) {
  553. tryEnsureConfigReady();
  554. }
  555. }
  556. /**
  557. * 透传 JSAPI 调用
  558. */ async function passthrough(name, params, jsapiParams = params) {
  559. return promiseToCallback(params, async ()=>{
  560. await tryEnsureConfigReady();
  561. return invoke(name, jsapiParams);
  562. });
  563. }
  564. /**
  565. * 绑定事件
  566. */ async function bindShare(name, params, handler) {
  567. await tryEnsureConfigReady();
  568. on(name, ()=>{
  569. promiseToCallback(params, handler);
  570. });
  571. }
  572. /**
  573. * 把 promise 转为 success/fail callbacak 回调
  574. */ function promiseToCallback(params, factory) {
  575. return factory(params).then((result)=>{
  576. safeRun(params?.success, result);
  577. safeRun(params?.complete, result);
  578. return result;
  579. }, (error)=>{
  580. const keyword = extractErrMsgKeyword(error.errMsg);
  581. if (keyword === 'cancel') {
  582. safeRun(params?.cancel, error);
  583. } else {
  584. safeRun(params?.fail, error);
  585. }
  586. safeRun(params?.complete, error);
  587. throw error;
  588. });
  589. }
  590. exports.Proximity = void 0;
  591. (function(Proximity) {
  592. /**
  593. * CLProximityUnknown
  594. */ Proximity["CLProximityUnknown"] = "0";
  595. /**
  596. * CLProximityImmediate
  597. */ Proximity["CLProximityImmediate"] = "1";
  598. /**
  599. * CLProximityNear
  600. */ Proximity["CLProximityNear"] = "2";
  601. /**
  602. * CLProximityFar
  603. */ Proximity["CLProximityFar"] = "3";
  604. })(exports.Proximity || (exports.Proximity = {}));
  605. /**
  606. * 开启查找周边 iBeacon 设备。
  607. *
  608. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
  609. * @compat WeChat
  610. */ function startSearchBeacons(params = {}) {
  611. return passthrough('startMonitoringBeacons', params);
  612. }
  613. /**
  614. * 关闭查找周边 iBeacon 设备。
  615. *
  616. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
  617. * @compat WeChat
  618. */ function stopSearchBeacons(params = {}) {
  619. return passthrough('stopMonitoringBeacons', params);
  620. }
  621. /**
  622. * 监听周边 iBeacon 设备接口。
  623. *
  624. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
  625. * @compat WeChat
  626. */ function onSearchBeacons(callback) {
  627. on('onBeaconsInRange', callback);
  628. }
  629. /**
  630. * 连接低功耗蓝牙设备。
  631. *
  632. * @note
  633. * - 安卓手机上如果多次调用 createBLEConnection 创建连接,有可能导致系统持有同一设备多个连接的实例,导致调用 closeBLEConnection 的时候并不能真正的断开与设备的连接。因此请保证尽量成对的调用 create 和 close 接口
  634. * - 蓝牙链接随时可能断开,建议监听 onBLEConnectionStateChange 回调事件,当蓝牙设备断开时按需执行重连操作
  635. * - 若对未连接的设备或已断开连接的设备调用数据读写操作的接口,会返回 10006 错误,建议进行重连操作
  636. *
  637. * @compat WeCom
  638. *
  639. * @example
  640. * ```ts
  641. * ww.createBLEConnection({
  642. * deviceId: deviceId
  643. * })
  644. * ```
  645. */ function createBLEConnection(params) {
  646. return passthrough('createBLEConnection', params);
  647. }
  648. /**
  649. * 断开与低功耗蓝牙设备的连接。
  650. *
  651. * @compat WeCom
  652. *
  653. * @example
  654. * ```ts
  655. * ww.closeBLEConnection({
  656. * deviceId: deviceId
  657. * })
  658. * ```
  659. */ function closeBLEConnection(params) {
  660. return passthrough('closeBLEConnection', params);
  661. }
  662. /**
  663. * 监听低功耗蓝牙连接状态的改变事件,包括开发者主动连接或断开连接,设备丢失,连接异常断开等等。
  664. *
  665. * @compat WeCom
  666. *
  667. * @example
  668. * ```ts
  669. * ww.onBLEConnectionStateChange(function(event) {
  670. * console.log(event)
  671. * })
  672. * ```
  673. */ function onBLEConnectionStateChange(callback) {
  674. on('onBLEConnectionStateChange', callback);
  675. }
  676. /**
  677. * 获取蓝牙设备所有 service(服务)。
  678. *
  679. * @compat WeCom
  680. *
  681. * @example
  682. * ```ts
  683. * ww.getBLEDeviceServices({
  684. * deviceId: deviceId
  685. * })
  686. * ```
  687. */ function getBLEDeviceServices(params) {
  688. return passthrough('getBLEDeviceServices', params);
  689. }
  690. /**
  691. * 获取蓝牙设备某个服务中的所有 characteristic(特征值)。
  692. *
  693. * @compat WeCom
  694. *
  695. * @example
  696. * ```ts
  697. * ww.getBLEDeviceCharacteristics({
  698. * deviceId: deviceId,
  699. * serviceId: serviceId
  700. * })
  701. * ```
  702. */ function getBLEDeviceCharacteristics(params) {
  703. return passthrough('getBLEDeviceCharacteristics', params);
  704. }
  705. /**
  706. * 读取低功耗蓝牙设备的特征值的二进制数据值。
  707. *
  708. * @note
  709. * - 设备的特征值必须支持 read 才可以成功调用,具体参照 characteristic 的 properties 属性
  710. * - 并行调用多次读写接口存在读写失败的可能性
  711. * - 接口读取到的信息需要在 onBLECharacteristicValueChange 的回调中获取
  712. *
  713. * @compat WeCom
  714. *
  715. * @example
  716. * ```ts
  717. * ww.readBLECharacteristicValue({
  718. * deviceId: deviceId,
  719. * serviceId: serviceId,
  720. * characteristicId: characteristicId
  721. * })
  722. * ```
  723. */ function readBLECharacteristicValue(params) {
  724. return passthrough('readBLECharacteristicValue', params);
  725. }
  726. /**
  727. * 向低功耗蓝牙设备特征值中写入二进制数据。
  728. *
  729. * @note
  730. * - 设备的特征值必须支持 write 才可以成功调用,具体参照 characteristic 的 properties 属性
  731. * - 并行调用多次读写接口存在读写失败的可能性
  732. * - 接口不会对写入数据包大小做限制,但系统与蓝牙设备会确定蓝牙 4.0 单次传输的数据大小,超过最大字节数后会发生写入错误,建议每次写入不超过 20 字节
  733. * - 安卓平台上,在调用 notify 成功后立即调用 write 接口,在部分机型上会发生 10008 系统错误
  734. * - 若单次写入数据过长,iOS 平台上存在系统不会有任何回调的情况(包括错误回调)
  735. *
  736. * @compat WeCom
  737. *
  738. * @example
  739. * ```ts
  740. * ww.writeBLECharacteristicValue({
  741. * deviceId: deviceId,
  742. * serviceId: serviceId,
  743. * characteristicId: characteristicId,
  744. * value: arrayBufferValue
  745. * })
  746. * ```
  747. */ function writeBLECharacteristicValue(params) {
  748. return passthrough('writeBLECharacteristicValue', params, {
  749. deviceId: params.deviceId,
  750. serviceId: params.serviceId,
  751. characteristicId: params.characteristicId,
  752. value: arrayBufferToBase64(params.value)
  753. });
  754. }
  755. /**
  756. * 启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。
  757. *
  758. * @note
  759. * - 设备的特征值必须支持 notify 或者 indicate 才可以成功调用,具体参照 characteristic 的 properties 属性
  760. * - 订阅操作成功后需要设备主动更新特征值的 value 才会触发 onBLECharacteristicValueChange 回调
  761. * - 安卓平台上,在调用 notify 成功后立即调用 write 接口,在部分机型上会发生 10008 系统错误
  762. *
  763. * @compat WeCom
  764. *
  765. * @example
  766. * ```ts
  767. * ww.notifyBLECharacteristicValueChange({
  768. * deviceId: deviceId,
  769. * serviceId: serviceId,
  770. * characteristicId: characteristicId,
  771. * state: true
  772. * })
  773. * ```
  774. */ function notifyBLECharacteristicValueChange(params) {
  775. return passthrough('notifyBLECharacteristicValueChange', params);
  776. }
  777. /**
  778. * 监听低功耗蓝牙设备的特征值变化。
  779. *
  780. * 必须先启用 notify 才能接收到设备推送的 notification。
  781. *
  782. * @compat WeCom
  783. *
  784. * @example
  785. * ```ts
  786. * ww.onBLECharacteristicValueChange(function(event) {
  787. * console.log(event)
  788. * })
  789. * ```
  790. */ function onBLECharacteristicValueChange(callback) {
  791. on('onBLECharacteristicValueChange', (event)=>{
  792. if (typeof event?.value === 'string') {
  793. event.value = base64ToArrayBuffer(event.value);
  794. }
  795. callback(event);
  796. });
  797. }
  798. /**
  799. * 初始化蓝牙模块。
  800. *
  801. * @compat WeCom
  802. *
  803. * @example
  804. * ```ts
  805. * ww.openBluetoothAdapter()
  806. * ```
  807. */ function openBluetoothAdapter(params = {}) {
  808. return passthrough('openBluetoothAdapter', params);
  809. }
  810. /**
  811. * 关闭蓝牙模块。
  812. *
  813. * @note
  814. * - 调用该方法将断开所有已建立的链接并释放系统资源
  815. *
  816. * @compat WeCom
  817. *
  818. * @example
  819. * ```ts
  820. * ww.closeBluetoothAdapter()
  821. * ```
  822. */ function closeBluetoothAdapter(params = {}) {
  823. return passthrough('closeBluetoothAdapter', params);
  824. }
  825. /**
  826. * 获取本机蓝牙适配器状态。
  827. *
  828. * @compat WeCom
  829. *
  830. * @example
  831. * ```ts
  832. * ww.getBluetoothAdapterState()
  833. * ```
  834. */ function getBluetoothAdapterState(params = {}) {
  835. return passthrough('getBluetoothAdapterState', params);
  836. }
  837. /**
  838. * 监听蓝牙适配器状态变化。
  839. *
  840. * @compat WeCom
  841. *
  842. * @example
  843. * ```ts
  844. * ww.onBluetoothAdapterStateChange(function(event) {
  845. * console.log(event)
  846. * })
  847. * ```
  848. */ function onBluetoothAdapterStateChange(callback) {
  849. on('onBluetoothAdapterStateChange', callback);
  850. }
  851. /**
  852. * 开始搜寻附近的蓝牙外围设备。
  853. *
  854. * @compat WeCom
  855. *
  856. * @example
  857. * ```ts
  858. * ww.startBluetoothDevicesDiscovery({
  859. * services: ['FEE7']
  860. * })
  861. * ```
  862. */ function startBluetoothDevicesDiscovery(params = {}) {
  863. return passthrough('startBluetoothDevicesDiscovery', params);
  864. }
  865. /**
  866. * 停止搜寻附近的蓝牙外围设备。
  867. *
  868. * 若已经找到需要的蓝牙设备并不需要继续搜索时,建议调用该接口停止蓝牙搜索。
  869. *
  870. * @compat WeCom
  871. *
  872. * @example
  873. * ```ts
  874. * ww.stopBluetoothDevicesDiscovery()
  875. * ```
  876. */ function stopBluetoothDevicesDiscovery(params = {}) {
  877. return passthrough('stopBluetoothDevicesDiscovery', params);
  878. }
  879. /**
  880. * 获取在蓝牙模块生效期间所有已发现的蓝牙设备。
  881. *
  882. * @note
  883. * - 该接口获取到的设备列表为蓝牙模块生效期间所有搜索到的蓝牙设备,若在蓝牙模块使用流程结束后未及时调用 closeBluetoothAdapter 释放资源,调用该接口可能会返回之前蓝牙使用流程中搜索到的蓝牙设备,可能设备已经不在用户身边,无法连接
  884. * - 蓝牙设备在被搜索到时,系统返回的 name 字段一般为广播包中的 LocalName 字段中的设备名称,而如果与蓝牙设备建立连接,系统返回的 name 字段会改为从蓝牙设备上获取到的 GattName。若需要动态改变设备名称并展示,建议使用 localName 字段
  885. *
  886. * @compat WeCom
  887. *
  888. * @example
  889. * ```ts
  890. * ww.getBluetoothDevices()
  891. * ```
  892. */ function getBluetoothDevices(params = {}) {
  893. return promiseToCallback(params, async ()=>{
  894. await tryEnsureConfigReady();
  895. const res = await invoke('getBluetoothDevices');
  896. for (const device of res.devices || []){
  897. normalizeBluetoothDevice(device);
  898. }
  899. return res;
  900. });
  901. }
  902. /**
  903. * 监听寻找到新设备。
  904. *
  905. * @note
  906. * - 若在该接口中回调了某个设备,则此设备会添加到 getBluetoothDevices 接口返回的设备列表中
  907. *
  908. * @compat WeCom
  909. *
  910. * @example
  911. * ```ts
  912. * ww.onBluetoothDeviceFound(function(event) {
  913. * console.log(event)
  914. * })
  915. * ```
  916. */ function onBluetoothDeviceFound(callback) {
  917. on('onBluetoothDeviceFound', (res)=>{
  918. for (const device of res.devices || []){
  919. normalizeBluetoothDevice(device);
  920. }
  921. callback(res);
  922. });
  923. }
  924. /**
  925. * 根据 uuid 获取处于已连接状态的设备。
  926. *
  927. * @compat WeCom
  928. *
  929. * @example
  930. * ```ts
  931. * ww.getConnectedBluetoothDevices({
  932. * services: ['FEE7']
  933. * })
  934. * ```
  935. */ function getConnectedBluetoothDevices(params) {
  936. return passthrough('getConnectedBluetoothDevices', params);
  937. }
  938. function normalizeBluetoothDevice(device) {
  939. if (typeof device.advertisData === 'string') {
  940. device.advertisData = base64ToArrayBuffer(device.advertisData);
  941. }
  942. /**
  943. * @desc 客户端返回字段为 serviceDataV2,sdk 统一转换为 serviceData 字段后对外返回
  944. */ if (device.serviceDataV2) {
  945. const finalServiceData = device.serviceDataV2;
  946. for (const key of Object.keys(finalServiceData)){
  947. if (typeof finalServiceData[key] === 'string') {
  948. finalServiceData[key] = base64ToArrayBuffer(finalServiceData[key]);
  949. }
  950. }
  951. device.serviceData = finalServiceData;
  952. delete device.serviceDataV2;
  953. }
  954. }
  955. /**
  956. * 设置系统剪贴板的内容。
  957. *
  958. * @compat WeCom iOS, Android >= 2.4.16; WeCom PC, Mac >= 3.1.2
  959. *
  960. * @example
  961. * ```ts
  962. * ww.setClipboardData({
  963. * data: 'data'
  964. * })
  965. * ```
  966. */ function setClipboardData(params) {
  967. return passthrough('setClipboardData', params);
  968. }
  969. /**
  970. * 获取系统剪贴板内容。
  971. *
  972. * @compat WeCom >= 3.1.2
  973. *
  974. * @example
  975. * ```ts
  976. * ww.getClipboardData()
  977. * ```
  978. */ function getClipboardData(params = {}) {
  979. return passthrough('getClipboardData', params);
  980. }
  981. /**
  982. * 开始搜索附近的 iBeacon 设备。
  983. *
  984. * @compat WeCom
  985. *
  986. * @example
  987. * ```ts
  988. * ww.startBeaconDiscovery({
  989. * uuids: ['uuid']
  990. * })
  991. * ```
  992. */ function startBeaconDiscovery(params) {
  993. return passthrough('startBeaconDiscovery', params);
  994. }
  995. /**
  996. * 停止搜索附近的 iBeacon 设备。
  997. *
  998. * @compat WeCom
  999. *
  1000. * @example
  1001. * ```ts
  1002. * ww.stopBeaconDiscovery()
  1003. * ```
  1004. */ function stopBeaconDiscovery(params = {}) {
  1005. return passthrough('stopBeaconDiscovery', params);
  1006. }
  1007. /**
  1008. * 获取所有已搜索到的 iBeacon 设备。
  1009. *
  1010. * @compat WeCom
  1011. *
  1012. * @example
  1013. * ```ts
  1014. * ww.getBeacons()
  1015. * ```
  1016. */ function getBeacons(params = {}) {
  1017. return passthrough('getBeacons', params);
  1018. }
  1019. /**
  1020. * 监听 iBeacon 设备的更新事件。
  1021. *
  1022. * @compat WeCom
  1023. *
  1024. * @example
  1025. * ```ts
  1026. * ww.onBeaconUpdate(function(event) {
  1027. * console.log(event)
  1028. * })
  1029. * ```
  1030. */ function onBeaconUpdate(callback) {
  1031. on('onBeaconUpdate', callback);
  1032. }
  1033. /**
  1034. * 监听 iBeacon 服务的状态变化。
  1035. *
  1036. * @compat WeCom
  1037. *
  1038. * @example
  1039. * ```ts
  1040. * ww.onBeaconServiceChange(function(event) {
  1041. * console.log(event)
  1042. * })
  1043. * ```
  1044. */ function onBeaconServiceChange(callback) {
  1045. on('onBeaconServiceChange', callback);
  1046. }
  1047. exports.LocationType = void 0;
  1048. (function(LocationType) {
  1049. /**
  1050. * gps 坐标
  1051. */ LocationType["wgs84"] = "wgs84";
  1052. /**
  1053. * 火星坐标
  1054. */ LocationType["gcj02"] = "gcj02";
  1055. })(exports.LocationType || (exports.LocationType = {}));
  1056. /**
  1057. * 使用企业微信内置地图查看位置。
  1058. *
  1059. * @example
  1060. * ```ts
  1061. * ww.openLocation({
  1062. * latitude: 0,
  1063. * longitude: 0,
  1064. * name: 'name',
  1065. * address: 'address',
  1066. * scale: 1
  1067. * })
  1068. * ```
  1069. */ function openLocation(params) {
  1070. return passthrough('openLocation', params, {
  1071. latitude: params.latitude,
  1072. longitude: params.longitude,
  1073. name: params.name || '',
  1074. address: params.address || '',
  1075. scale: params.scale || 28,
  1076. infoUrl: params.infoUrl || ''
  1077. });
  1078. }
  1079. /**
  1080. * 获取地理位置。
  1081. *
  1082. * @example
  1083. * ```ts
  1084. * ww.getLocation({
  1085. * type: 'wgs84'
  1086. * })
  1087. * ```
  1088. */ function getLocation(params = {}) {
  1089. return promiseToCallback(params, async ()=>{
  1090. await tryEnsureConfigReady();
  1091. const res = await invoke('geoLocation', {
  1092. type: params.type || 'wgs84'
  1093. });
  1094. delete res.type;
  1095. return res;
  1096. });
  1097. }
  1098. /**
  1099. * 打开持续定位。
  1100. *
  1101. * @compat WeCom >= 2.4.20
  1102. *
  1103. * @example
  1104. * ```ts
  1105. * ww.startAutoLBS({
  1106. * type: 'gcj02'
  1107. * })
  1108. * ```
  1109. */ function startAutoLBS(params) {
  1110. return passthrough('startAutoLBS', params);
  1111. }
  1112. /**
  1113. * 停止持续定位。
  1114. *
  1115. * @compat WeCom >= 2.4.20
  1116. *
  1117. * @example
  1118. * ```ts
  1119. * ww.stopAutoLBS()
  1120. * ```
  1121. */ function stopAutoLBS(params = {}) {
  1122. return passthrough('stopAutoLBS', params);
  1123. }
  1124. /**
  1125. * 监听地理位置的变化。
  1126. *
  1127. * @limit
  1128. * - 需要提前调用 startAutoLBS
  1129. * - 需要用户停留在当前页面
  1130. *
  1131. * @compat WeCom >= 2.4.20
  1132. *
  1133. * @example
  1134. * ```ts
  1135. * ww.onLocationChange(function(event) {
  1136. * console.log(event)
  1137. * })
  1138. * ```
  1139. *
  1140. * @throws
  1141. * | errMsg | 说明 | 兼容性 |
  1142. * | --- | --- | --- |
  1143. * | auto:location:report:ok | 执行成功 | |
  1144. * | auto:location:report:fail, gps closed. | 用户关闭了 GPS | 企业微信 3.0.26 |
  1145. */ function onLocationChange(callback) {
  1146. on('auto:location:report', callback);
  1147. }
  1148. exports.NetworkType = void 0;
  1149. (function(NetworkType) {
  1150. /**
  1151. * wifi
  1152. */ NetworkType["wifi"] = "wifi";
  1153. /**
  1154. * 2g
  1155. */ NetworkType["network2g"] = "2g";
  1156. /**
  1157. * 3g
  1158. */ NetworkType["network3g"] = "3g";
  1159. /**
  1160. * 4g
  1161. */ NetworkType["network4g"] = "4g";
  1162. /**
  1163. * 无网络
  1164. */ NetworkType["none"] = "none";
  1165. /**
  1166. * Android下不常见的网络类型
  1167. */ NetworkType["unknown"] = "unknown";
  1168. })(exports.NetworkType || (exports.NetworkType = {}));
  1169. /**
  1170. * 获取网络状态。
  1171. *
  1172. * @compat WeCom iOS, Android; WeChat
  1173. *
  1174. * @example
  1175. * ```ts
  1176. * ww.getNetworkType()
  1177. * ```
  1178. */ function getNetworkType(params = {}) {
  1179. return passthrough('getNetworkType', params);
  1180. }
  1181. /**
  1182. * 监听网络状态变化。
  1183. *
  1184. * @compat WeCom iOS, Android
  1185. *
  1186. * @example
  1187. * ```ts
  1188. * ww.onNetworkStatusChange(function(event) {
  1189. * console.log(event)
  1190. * })
  1191. * ```
  1192. */ function onNetworkStatusChange(callback) {
  1193. on('onNetworkStatusChange', callback);
  1194. }
  1195. /**
  1196. * 初始化 Wi-Fi 模块。
  1197. *
  1198. * @compat WeCom iOS, Android >= 2.4.16
  1199. *
  1200. * @example
  1201. * ```ts
  1202. * ww.startWifi()
  1203. * ```
  1204. */ function startWifi(params = {}) {
  1205. return passthrough('startWifi', params);
  1206. }
  1207. /**
  1208. * 关闭 Wi-Fi 模块。
  1209. *
  1210. * @compat WeCom iOS, Android >= 2.4.16
  1211. *
  1212. * @example
  1213. * ```ts
  1214. * ww.stopWifi()
  1215. * ```
  1216. */ function stopWifi(params = {}) {
  1217. return passthrough('stopWifi', params);
  1218. }
  1219. /**
  1220. * 连接 Wi-Fi。
  1221. *
  1222. * @compat WeCom iOS, Android >= 2.4.16
  1223. *
  1224. * @example
  1225. * ```ts
  1226. * ww.connectWifi({
  1227. * SSID: 'vincenthome',
  1228. * BSSID: '8c:a6:df:c8:f7:4b',
  1229. * password: 'test1234',
  1230. * })
  1231. * ```
  1232. */ function connectWifi(params) {
  1233. return passthrough('connectWifi', params);
  1234. }
  1235. /**
  1236. * 获取 Wi-Fi 列表。
  1237. *
  1238. * @compat WeCom iOS, Android >= 2.4.16
  1239. *
  1240. * @example
  1241. * ```ts
  1242. * ww.getWifiList()
  1243. * ```
  1244. */ function getWifiList(params = {}) {
  1245. return passthrough('getWifiList', params);
  1246. }
  1247. /**
  1248. * 监听 Wi-Fi 列表更新。
  1249. *
  1250. * @compat WeCom iOS, Android >= 2.4.16
  1251. *
  1252. * @example
  1253. * ```ts
  1254. * ww.onGetWifiList(function(event) {
  1255. * console.log(event)
  1256. * })
  1257. * ```
  1258. */ function onGetWifiList(callback) {
  1259. on('onGetWifiList', callback);
  1260. }
  1261. /**
  1262. * 监听 Wi-Fi 连接成功。
  1263. *
  1264. * @compat WeCom iOS, Android >= 2.4.16
  1265. *
  1266. * @example
  1267. * ```ts
  1268. * ww.onWifiConnected(function(event) {
  1269. * console.log(event)
  1270. * })
  1271. * ```
  1272. */ function onWifiConnected(callback) {
  1273. on('onWifiConnected', callback);
  1274. }
  1275. /**
  1276. * 获取已连接中的 Wi-Fi 信息。
  1277. *
  1278. * @compat WeCom iOS, Android >= 2.4.16
  1279. *
  1280. * @example
  1281. * ```ts
  1282. * ww.getConnectedWifi()
  1283. * ```
  1284. */ function getConnectedWifi(params = {}) {
  1285. return passthrough('getConnectedWifi', params);
  1286. }
  1287. /**
  1288. * 预览文件
  1289. *
  1290. * @compat WeCom iOS, Android
  1291. *
  1292. * @note
  1293. * 本接口将 URL 对应的文件下载后,在内置浏览器中预览。目前支持图片、音频、视频、文档等格式的文件。
  1294. * 从 2.4.6 版本开始,iOS 版企业微信浏览器升级为 WkWebView,企业微信原生层面的网络请求读取不到WKWebview中设置的cookie,即使域名是相同的。
  1295. * **问题说明:**
  1296. * 如果页面的资源或图片存储的服务器依赖校验Cookie来返回数据的情况,在切换到WKWebview后,在企业微信内长按保存,或者点击预览文件时,原生层面发起的网络请求将不会完整地带上所设置的Cookie,会导致图片保存失败或预览失败。
  1297. * **适配建议:**
  1298. * 建议静态资源cookie free。如果确实有信息需要传递,可通过业务后台存储需要传递的信息,然后给页面一个存储信息相对应的access_token加密码,再通过Url中加入自己业务的access_token进行页面间信息传递。
  1299. *
  1300. * @example
  1301. * ```ts
  1302. * ww.previewFile({
  1303. * url: 'http://open.work.weixin.qq.com/wwopen/downloadfile/wwapi.zip',
  1304. * name: 'Android开发工具包集合',
  1305. * size: 22189
  1306. * })
  1307. * ```
  1308. */ function previewFile(params) {
  1309. return passthrough('previewFile', params);
  1310. }
  1311. exports.ChooseMessageFileType = void 0;
  1312. (function(ChooseMessageFileType) {
  1313. /**
  1314. * 仅选择视频文件
  1315. */ ChooseMessageFileType["video"] = "video";
  1316. /**
  1317. * 仅选择图片文件
  1318. */ ChooseMessageFileType["image"] = "image";
  1319. /**
  1320. * 可选择除了图片和视频之外的其它的文件
  1321. */ ChooseMessageFileType["file"] = "file";
  1322. /**
  1323. * 可同时选择视频与图片
  1324. */ ChooseMessageFileType["video_and_image"] = "video_and_image";
  1325. })(exports.ChooseMessageFileType || (exports.ChooseMessageFileType = {}));
  1326. exports.TempFileType = void 0;
  1327. (function(TempFileType) {
  1328. /**
  1329. * 视频文件
  1330. */ TempFileType["video"] = "video";
  1331. /**
  1332. * 图片文件
  1333. */ TempFileType["image"] = "image";
  1334. /**
  1335. * 除图片和视频的文件
  1336. */ TempFileType["file"] = "file";
  1337. })(exports.TempFileType || (exports.TempFileType = {}));
  1338. /**
  1339. * 从企业微信会话中选择文件,用户选择文件之后,返回临时文件 localId,可再调用 [getLocalFileData](#56784) 获取文件内容。
  1340. *
  1341. * @compat WeCom iOS, Android >= 4.0.20
  1342. *
  1343. * @limit
  1344. * - 本接口必须使用应用身份进行注册
  1345. * - 当前成员必须在应用的可见范围之中
  1346. *
  1347. * @example
  1348. * ```ts
  1349. * ww.chooseMessageFile({
  1350. * count: 10,
  1351. * type: 'image',
  1352. * })
  1353. * ```
  1354. */ function chooseMessageFile(params) {
  1355. return passthrough('chooseMessageFile', params);
  1356. }
  1357. /**
  1358. * 获取 chooseMessageFile 返回的 localId 对应的文件内容。
  1359. *
  1360. * @compat WeCom iOS, Android >= 4.0.20
  1361. *
  1362. * @limit
  1363. * - 本接口必须使用应用身份进行注册
  1364. * - 当前成员必须在应用的可见范围之中
  1365. *
  1366. * @example
  1367. * ```ts
  1368. * ww.getLocalFileData({
  1369. * localId: '',
  1370. * })
  1371. * ```
  1372. *
  1373. * @throws
  1374. * | errMsg | 说明 |
  1375. * | --- | --- |
  1376. * | getLocalFileData:ok | 执行成功 |
  1377. * | no permission | 应用签名校验失败,或成员不在应用的可见范围内 |
  1378. * | no such file | localId不存在或者文件已删除 |
  1379. * | file exceed size limit | 不支持超过20M的文件 |
  1380. */ function getLocalFileData(params) {
  1381. return passthrough('getLocalFileData', params);
  1382. }
  1383. exports.SizeType = void 0;
  1384. (function(SizeType) {
  1385. /**
  1386. * 原图
  1387. */ SizeType["original"] = "original";
  1388. /**
  1389. * 压缩后的图片
  1390. */ SizeType["compressed"] = "compressed";
  1391. })(exports.SizeType || (exports.SizeType = {}));
  1392. exports.SourceType = void 0;
  1393. (function(SourceType) {
  1394. /**
  1395. * 相册
  1396. */ SourceType["album"] = "album";
  1397. /**
  1398. * 相机,企业微信 2.3 及以后版本支持相机连拍
  1399. */ SourceType["camera"] = "camera";
  1400. })(exports.SourceType || (exports.SourceType = {}));
  1401. exports.CameraMode = void 0;
  1402. (function(CameraMode) {
  1403. /**
  1404. * 单拍
  1405. */ CameraMode["normal"] = "normal";
  1406. /**
  1407. * 连拍
  1408. *
  1409. * @compat WeCom >= 2.3.0
  1410. */ CameraMode["batch"] = "batch";
  1411. /**
  1412. * 前置摄像头单拍
  1413. *
  1414. * @compat WeCom >= 3.0.26
  1415. */ CameraMode["front"] = "front";
  1416. /**
  1417. * 前置摄像头连拍
  1418. *
  1419. * @compat WeCom >= 3.0.26
  1420. */ CameraMode["batch_front"] = "batch_front";
  1421. })(exports.CameraMode || (exports.CameraMode = {}));
  1422. /**
  1423. * 拍照或从手机相册中选图。
  1424. *
  1425. * @compat WeCom iOS, Android; WeChat
  1426. *
  1427. * @example
  1428. * ```ts
  1429. * ww.chooseImage({
  1430. * count: 1,
  1431. * sizeType: ['original', 'compressed'],
  1432. * sourceType: ['album', 'camera'],
  1433. * defaultCameraMode: 'batch',
  1434. * isSaveToAlbum: true
  1435. * })
  1436. * ```
  1437. */ function chooseImage(params = {}) {
  1438. return promiseToCallback(params, async ()=>{
  1439. await tryEnsureConfigReady();
  1440. const res = await invoke('chooseImage', {
  1441. scene: '1|2',
  1442. count: params.count || 9,
  1443. sizeType: params.sizeType || [
  1444. 'original',
  1445. 'compressed'
  1446. ],
  1447. sourceType: params.sourceType || [
  1448. 'album',
  1449. 'camera'
  1450. ],
  1451. defaultCameraMode: params.defaultCameraMode || 'normal',
  1452. isSaveToAlbum: isFalsy(params.isSaveToAlbum) ? 0 : 1
  1453. });
  1454. if (isAndroid && res.localIds) {
  1455. res.localIds = res.localIds || '[]';
  1456. try {
  1457. res.localIds = JSON.parse(res.localIds);
  1458. } catch (error) {
  1459. // noop
  1460. }
  1461. }
  1462. return res;
  1463. });
  1464. }
  1465. /**
  1466. * 预览图片
  1467. *
  1468. * @note
  1469. * 从2.4.6版本开始,IOS版企业微信浏览器升级为WkWebView,企业微信原生层面的网络请求读取不到WKWebview中设置的cookie,即使域名是相同的。
  1470. * **问题说明:**
  1471. * 如果页面的资源或图片存储的服务器依赖校验Cookie来返回数据的情况,在切换到WKWebview后,在企业微信内长按保存,或者点击预览大图时,原生层面发起的网络请求将不会完整地带上所设置的Cookie,会导致图片保存失败或预览失败。
  1472. * **适配建议**
  1473. * 建议静态资源cookie free。如果确实有信息需要传递,可通过业务后台存储需要传递的信息,然后给页面一个存储信息相对应的access_token加密码,再通过Url中加入自己业务的access_token进行页面间信息传递。
  1474. *
  1475. * @example
  1476. * ```ts
  1477. * ww.previewImage({
  1478. * current: imgURL,
  1479. * urls: [imgURL]
  1480. * });
  1481. * ```
  1482. */ function previewImage(params) {
  1483. return passthrough('imagePreview', params);
  1484. }
  1485. /**
  1486. * 上传图片。
  1487. *
  1488. * @note
  1489. * 上传的图片有效期 3 天,可用[素材管理](#10115)接口下载图片到自己的服务器,此处获得的 serverId 即 media_id。
  1490. *
  1491. * @example
  1492. * ```ts
  1493. * ww.uploadImage({
  1494. * localId: localId,
  1495. * isShowProgressTips: true
  1496. * })
  1497. * ```
  1498. */ function uploadImage(params) {
  1499. return passthrough('uploadImage', params, {
  1500. localId: params.localId,
  1501. isShowProgressTips: isFalsy(params.isShowProgressTips) ? 0 : 1
  1502. });
  1503. }
  1504. /**
  1505. * 下载图片。
  1506. *
  1507. * @example
  1508. * ```ts
  1509. * ww.downloadImage({
  1510. * serverId: serverId,
  1511. * isShowProgressTips: true
  1512. * })
  1513. * ```
  1514. */ function downloadImage(params) {
  1515. return passthrough('downloadImage', params, {
  1516. serverId: params.serverId,
  1517. isShowProgressTips: isFalsy(params.isShowProgressTips) ? 0 : 1
  1518. });
  1519. }
  1520. /**
  1521. * 获取本地图片内容。
  1522. *
  1523. * @limit
  1524. * 仅在 iOS WKWebView 下支持。
  1525. *
  1526. * @compat WeCom iOS >= 2.4.6
  1527. *
  1528. * @example
  1529. * ```ts
  1530. * ww.getLocalImgData({
  1531. * localId: localId
  1532. * })
  1533. * ```
  1534. */ function getLocalImgData(params) {
  1535. return passthrough('getLocalImgData', params);
  1536. }
  1537. /**
  1538. * 开始录音。
  1539. *
  1540. * @example
  1541. * ```ts
  1542. * ww.startRecord()
  1543. * ```
  1544. */ function startRecord(params = {}) {
  1545. return passthrough('startRecord', params);
  1546. }
  1547. /**
  1548. * 停止录音。
  1549. *
  1550. * @example
  1551. * ```ts
  1552. * ww.stopRecord()
  1553. * ```
  1554. */ function stopRecord(params = {}) {
  1555. return passthrough('stopRecord', params);
  1556. }
  1557. /**
  1558. * 监听录音自动停止。
  1559. *
  1560. * @note
  1561. * 录音时间超过一分钟没有停止的时候会执行 complete 回调
  1562. *
  1563. * @example
  1564. * ```ts
  1565. * ww.onVoiceRecordEnd(function(event) {
  1566. * console.log(event)
  1567. * })
  1568. * ```
  1569. */ function onVoiceRecordEnd(callback) {
  1570. on('onVoiceRecordEnd', callback);
  1571. }
  1572. /**
  1573. * 播放语音。
  1574. *
  1575. * @example
  1576. * ```ts
  1577. * ww.playVoice({
  1578. * localId: localId
  1579. * })
  1580. * ```
  1581. */ function playVoice(params) {
  1582. return passthrough('playVoice', params);
  1583. }
  1584. /**
  1585. * 暂停播放。
  1586. *
  1587. * @example
  1588. * ```ts
  1589. * ww.pauseVoice({
  1590. * localId: localId
  1591. * })
  1592. * ```
  1593. */ function pauseVoice(params) {
  1594. return passthrough('pauseVoice', params);
  1595. }
  1596. /**
  1597. * 停止播放。
  1598. *
  1599. * @example
  1600. * ```ts
  1601. * ww.stopVoice({
  1602. * localId: localId
  1603. * })
  1604. * ```
  1605. */ function stopVoice(params) {
  1606. return passthrough('stopVoice', params);
  1607. }
  1608. /**
  1609. * 监听语音播放完毕。
  1610. *
  1611. * @example
  1612. * ```ts
  1613. * ww.onVoicePlayEnd(function(event) {
  1614. * console.log(event)
  1615. * })
  1616. * ```
  1617. */ function onVoicePlayEnd(callback) {
  1618. on('onVoicePlayEnd', callback);
  1619. }
  1620. /**
  1621. * 上传语音。
  1622. *
  1623. * @note
  1624. * 上传语音有效期 3 天,可以通过[素材管理](https://developer.work.weixin.qq.com/document/path/91054)接口下载语音到自己的服务器,接口返回的的 `serverId` 即 `media_id`。
  1625. *
  1626. * @example
  1627. * ```ts
  1628. * ww.uploadVoice({
  1629. * localId: localId,
  1630. * isShowProgressTips: true
  1631. * })
  1632. * ```
  1633. */ function uploadVoice(params) {
  1634. return passthrough('uploadVoice', params, {
  1635. localId: params.localId,
  1636. isShowProgressTips: isFalsy(params.isShowProgressTips) ? 0 : 1
  1637. });
  1638. }
  1639. /**
  1640. * 下载语音。
  1641. *
  1642. * @example
  1643. * ```ts
  1644. * ww.downloadVoice({
  1645. * serverId: serverId,
  1646. * isShowProgressTips: true
  1647. * })
  1648. * ```
  1649. */ function downloadVoice(params) {
  1650. return passthrough('downloadVoice', params, {
  1651. serverId: params.serverId,
  1652. isShowProgressTips: isFalsy(params.isShowProgressTips) ? 0 : 1
  1653. });
  1654. }
  1655. /**
  1656. * 语音转文字。
  1657. *
  1658. * @compat WeCom iOS, Android >= 2.7.5
  1659. *
  1660. * @example
  1661. * ```ts
  1662. * ww.translateVoice({
  1663. * localId: localId,
  1664. * isShowProgressTips: true
  1665. * })
  1666. * ```
  1667. */ function translateVoice(params) {
  1668. return passthrough('translateVoice', params, {
  1669. localId: params.localId,
  1670. isShowProgressTips: isFalsy(params.isShowProgressTips) ? 0 : 1
  1671. });
  1672. }
  1673. exports.LiveType = void 0;
  1674. (function(LiveType) {
  1675. /**
  1676. * 通用直播
  1677. */ LiveType[LiveType["common"] = 0] = "common";
  1678. /**
  1679. * 企业培训
  1680. */ LiveType[LiveType["corp_training"] = 1] = "corp_training";
  1681. /**
  1682. * 大班课
  1683. */ LiveType[LiveType["edu_normal_class"] = 2] = "edu_normal_class";
  1684. /**
  1685. * 小班课
  1686. */ LiveType[LiveType["edu_small_class"] = 3] = "edu_small_class";
  1687. })(exports.LiveType || (exports.LiveType = {}));
  1688. function startLiving(params = {}) {
  1689. return passthrough('startLiving', params);
  1690. }
  1691. /**
  1692. * 调起直播间回放页面。
  1693. *
  1694. * @limit
  1695. * - 本接口必须使用应用身份进行注册
  1696. * - 应用需具有直播使用权限,参考[配置可使用直播的应用](#25967/配置可使用直播的应用)
  1697. *
  1698. * @compat WeCom >= 3.1.0
  1699. *
  1700. * @example
  1701. * ```ts
  1702. * ww.replayLiving({
  1703. * livingId: 'LIVINGID'
  1704. * })
  1705. * ```
  1706. *
  1707. * @throws
  1708. * | errMsg | 说明 |
  1709. * | --- | --- |
  1710. * | replayLiving:ok | 执行成功 |
  1711. * | replayLiving:fail no permission | 应用签名校验失败,或应用不具备直播权限 |
  1712. * | replayLiving:fail invalid living id | 不合法的直播ID |
  1713. * | replayLiving:fail not allow to cross corp | 不可跨企业使用直播ID |
  1714. * | replayLiving:fail not allow to cross app | 不可跨应用使用直播ID |
  1715. * | replayLiving:fail living has no replay | 不存在直播回放 |
  1716. * | replayLiving:fail replay is beging creating | 正在直播中,或回放正在生成中,稍后观看回放 |
  1717. * | replayLiving:fail create replay failed | 回放创建失败 |
  1718. * | replayLiving:fail invalid parameter | 参数不合法 |
  1719. */ function replayLiving(params) {
  1720. return passthrough('replayLiving', params);
  1721. }
  1722. /**
  1723. * 调起直播回放下载页面。
  1724. *
  1725. * @limit
  1726. * - 本接口必须使用应用身份进行注册
  1727. * - 应用需具有直播使用权限,参考[配置可使用直播的应用](#25967/配置可使用直播的应用)
  1728. * - 只允许直播的发起人下载直播回放
  1729. *
  1730. * @compat WeCom PC >= 3.1.0
  1731. *
  1732. * @example
  1733. * ```ts
  1734. * ww.downloadLivingReplay({
  1735. * livingId: 'LIVINGID'
  1736. * })
  1737. * ```
  1738. *
  1739. * @throws
  1740. * | errMsg | 说明 |
  1741. * | --- | --- |
  1742. * | downloadLivingReplay:ok | 执行成功 |
  1743. * | downloadLivingReplay:fail no permission | 应用签名校验失败,或应用不具备直播权限 |
  1744. * | downloadLivingReplay:fail invalid living id | 不合法的直播ID |
  1745. * | downloadLivingReplay:fail not allow to cross corp | 不可跨企业使用直播ID |
  1746. * | downloadLivingReplay:fail not allow to cross app | 不可跨应用使用直播ID |
  1747. * | downloadLivingReplay:fail invalid parameter | 参数不合法 |
  1748. * | downloadLivingReplay:fail living has no replay | 不存在直播回放 |
  1749. * | downloadLivingReplay:fail replay is beging creating | 正在直播中,或回放正在生成中,稍后观看回放 |
  1750. * | downloadLivingReplay:fail create replay failed | 回放创建失败 |
  1751. * | downloadLivingReplay:fail invalid operator | 只允许直播的发起人下载直播回放 |
  1752. */ function downloadLivingReplay(params) {
  1753. return passthrough('downloadLivingReplay', params);
  1754. }
  1755. function startMeeting(params = {}) {
  1756. return passthrough('startMeeting', params);
  1757. }
  1758. /**
  1759. * 新建文档、表格或者收集表。
  1760. *
  1761. * @limit
  1762. * - 本接口必须使用应用身份进行注册
  1763. * - 签名应用必须具有文档使用权限
  1764. * - 当前用户必须在应用的可见范围之内
  1765. * - 在 Mac 端使用时,macOS 版本需 > 10.12
  1766. *
  1767. * @compat WeCom >= 4.1.0
  1768. *
  1769. * @example
  1770. * ```
  1771. * ww.createDoc({
  1772. * docType: 3
  1773. * })
  1774. * ```
  1775. *
  1776. * @throws
  1777. * | errMsg | 说明 |
  1778. * | --- | --- |
  1779. * | createDoc:ok | 执行成功 |
  1780. * | createDoc:fail no permission | 应用签名校验失败,或成员不在应用的可见范围内,或应用未开启文档使用权限 |
  1781. * | createDoc:fail doc app closed. | 基础应用“文档”如果未启用 |
  1782. * | createDoc:fail form app closed. | 基础应用“收集表”如果没有启用 |
  1783. */ function createDoc(params) {
  1784. return passthrough('createDoc', params);
  1785. }
  1786. exports.WedocSelectedFileType = void 0;
  1787. (function(WedocSelectedFileType) {
  1788. /**
  1789. * 其他
  1790. */ WedocSelectedFileType[WedocSelectedFileType["other"] = 0] = "other";
  1791. /**
  1792. * 文档
  1793. */ WedocSelectedFileType[WedocSelectedFileType["doc"] = 3] = "doc";
  1794. /**
  1795. * 表格
  1796. */ WedocSelectedFileType[WedocSelectedFileType["sheet"] = 4] = "sheet";
  1797. /**
  1798. * 收集表
  1799. */ WedocSelectedFileType[WedocSelectedFileType["form"] = 5] = "form";
  1800. /**
  1801. * 幻灯片
  1802. */ WedocSelectedFileType[WedocSelectedFileType["slide"] = 6] = "slide";
  1803. /**
  1804. * 思维导图
  1805. */ WedocSelectedFileType[WedocSelectedFileType["mindmap"] = 7] = "mindmap";
  1806. /**
  1807. * 流程图
  1808. */ WedocSelectedFileType[WedocSelectedFileType["flowchart"] = 8] = "flowchart";
  1809. /**
  1810. * 智能表格
  1811. */ WedocSelectedFileType[WedocSelectedFileType["smartsheet"] = 10] = "smartsheet";
  1812. })(exports.WedocSelectedFileType || (exports.WedocSelectedFileType = {}));
  1813. /**
  1814. * 选择一个或多个文档,返回对应文档的 URL。
  1815. *
  1816. * @limit
  1817. * - 本接口必须使用应用身份进行注册,签名应用必须具有文档使用权限
  1818. * - 当前用户必须在应用的可见范围之内
  1819. * - Mac 端使用时,macOS 版本需 > 10.12
  1820. *
  1821. * @compat WeCom >= 4.0.12
  1822. *
  1823. * @example
  1824. * ```
  1825. * ww.wedocSelectDoc({
  1826. * selectedFileNum: 1
  1827. * })
  1828. * ```
  1829. *
  1830. * @throws
  1831. * | errMsg | 说明 |
  1832. * | --- | --- |
  1833. * | wedocSelectDoc:ok | 执行成功 |
  1834. * | wedocSelectDoc:cancel | 取消选择 |
  1835. * | wedocSelectDoc:fail no permission | 应用签名失败,或应用无文档使用权限,或用户不在应用可见范围内 |
  1836. * | wedocSelectDoc:fail param error | 参数错误 |
  1837. * | wedocSelectDoc:fail context error | 选择器异常 |
  1838. * | wedocSelectDoc:fail not supported system version| 低系统版本不支持 |
  1839. */ function wedocSelectDoc(params) {
  1840. return passthrough('wedocSelectDoc', params);
  1841. }
  1842. /**
  1843. * 在微盘中选择一个具有可上传权限的目录/空间,返回选中目录/空间对应的 selectedTicket。
  1844. *
  1845. * @limit
  1846. * - 本接口必须使用应用身份进行注册
  1847. * - 所使用的应用必须具有微盘权限
  1848. * - 当前成员必须在应用的可见范围之内
  1849. * - 若用户在某一目录位置不具备「上传」权限(微盘权限值为“可下载”/“仅预览”或自定义权限取消勾选“上传”权限),则无法选择该目录
  1850. * - 在 Mac 端使用时,macOS 版本需 > 10.12
  1851. *
  1852. * @compat WeCom >= 4.0.12
  1853. *
  1854. * @example
  1855. * ```
  1856. * ww.wedriveSelectDir()
  1857. * ```
  1858. *
  1859. * @throws
  1860. * | errMsg | 说明 |
  1861. * | --- | --- |
  1862. * | wedriveSelectDir:ok | 执行成功 |
  1863. * | wedriveSelectDir:cancel | 取消选择 |
  1864. * | wedriveSelectDir:fail no permission | 无权限 |
  1865. * | wedriveSelectDir:fail param error | 参数错误 |
  1866. * | wedriveSelectDir:fail context error | 选择器异常 |
  1867. * | wedriveSelectDir:fail not supported system version | 低系统版本不支持 |
  1868. */ function wedriveSelectDir(params = {}) {
  1869. return passthrough('wedriveSelectDir', params);
  1870. }
  1871. /**
  1872. * 唤起微盘选择器,选择微盘中的文件
  1873. *
  1874. * 在微盘中选择一个或多个具有可分享权限的微盘文件或在线文档,返回选中文件的 url。
  1875. *
  1876. * @compat WeCom >= 4.0.12
  1877. *
  1878. * @limit
  1879. * - 本接口必须使用应用身份进行注册
  1880. * - 所使用的应用必须具有微盘和文档使用权限
  1881. * - 当前成员必须在应用的可见范围之内
  1882. * - 若用户对某文件不具备「分享」权限(微盘自定义权限取消勾选“分享”权限),则无法选择该文件。
  1883. * - 在 Mac 端使用时,macOS 版本需 > 10.12
  1884. *
  1885. * @example
  1886. * ```
  1887. * ww.wedriveSelectFile({
  1888. * selectedFileNum: 1,
  1889. * })
  1890. * ```
  1891. *
  1892. * @throws
  1893. * | errMsg | 说明 |
  1894. * | --- | --- |
  1895. * | wedriveSelectFile:ok | 执行成功 |
  1896. * | wedriveSelectFile:cancel | 取消选择 |
  1897. * | wedriveSelectFile:fail no permission | 无权限 |
  1898. * | wedriveSelectFile:fail param error | 参数错误 |
  1899. * | wedriveSelectFile:fail context error | 选择器异常 |
  1900. * | wedriveSelectFile:fail not supported system version | 低系统版本不支持 |
  1901. */ function wedriveSelectFile(params) {
  1902. return passthrough('wedriveSelectFile', params);
  1903. }
  1904. /**
  1905. * 选择可分享的文件
  1906. *
  1907. * 在微盘中选择一个或多个具有可分享权限的微盘文件或在线文档,返回选中文件的 url。
  1908. *
  1909. * @deprecated 该接口即将废弃,请使用 wedriveSelectFile 代替
  1910. *
  1911. * @compat WeCom >= 4.0.12
  1912. */ function wedriveSelectFileForShare(params) {
  1913. return passthrough('wedriveSelectFileForShare', params);
  1914. }
  1915. /**
  1916. * 在微盘中选择一个或多个具有下载权限的文件(只能是微盘文件,不支持在线文档),返回选中文件对应的 selectedTickets 列表。
  1917. *
  1918. * @limit
  1919. * - 本接口必须使用应用身份进行注册
  1920. * - 应用必须具有微盘使用权限
  1921. * - 当前成员必须在应用的可见范围之中
  1922. * - 自建应用不支持调用
  1923. *
  1924. * @compat WeCom >= 4.0.12
  1925. *
  1926. * @example
  1927. * ```
  1928. * ww.wedriveSelectFileForDownload({
  1929. * selectedFileNum: 1
  1930. * })
  1931. * ```
  1932. *
  1933. * @throws
  1934. * | errMsg | 说明 |
  1935. * | --- | --- |
  1936. * | wedriveSelectFileForDownload:ok | 执行成功 |
  1937. * | wedriveSelectFileForDownload:cancel | 取消选择 |
  1938. * | wedriveSelectFileForDownload:fail no permission | 无权限 |
  1939. * | wedriveSelectFileForDownload:fail param error | 参数错误 |
  1940. * | wedriveSelectFileForDownload:fail context error | 选择器异常 |
  1941. * | wedriveSelectFileForDownload:fail not supported system version | 低系统版本不支持 |
  1942. */ function wedriveSelectFileForDownload(params) {
  1943. return passthrough('wedriveSelectFileForDownload', params);
  1944. }
  1945. /**
  1946. * 监听页面返回事件。
  1947. *
  1948. * @param callback 回调函数,返回 false 则表示中断此次返回操作
  1949. *
  1950. * @limit
  1951. * - 当页面左上角没有关闭按钮,不产生该事件
  1952. * - iOS 系统下使用手势返回时,不产生该事件
  1953. *
  1954. * @compat WeCom iOS, Android >= 2.2.0; WeCom PC, Mac >= 2.4.5
  1955. *
  1956. * @example
  1957. * ```ts
  1958. * ww.onHistoryBack(function() {
  1959. * return confirm('确定放弃当前页面的修改?')
  1960. * })
  1961. * ```
  1962. */ function onHistoryBack(callback) {
  1963. on('historyBack', callback);
  1964. }
  1965. /**
  1966. * 隐藏右上角菜单。
  1967. *
  1968. * @example
  1969. * ```ts
  1970. * ww.hideOptionMenu()
  1971. * ```
  1972. */ function hideOptionMenu(params = {}) {
  1973. return passthrough('hideOptionMenu', params);
  1974. }
  1975. /**
  1976. * 显示右上角菜单。
  1977. *
  1978. * @example
  1979. * ```ts
  1980. * ww.showOptionMenu()
  1981. * ```
  1982. */ function showOptionMenu(params = {}) {
  1983. return passthrough('showOptionMenu', params);
  1984. }
  1985. /**
  1986. * 关闭当前网页窗口。
  1987. *
  1988. * @example
  1989. * ```ts
  1990. * ww.closeWindow()
  1991. * ```
  1992. */ function closeWindow(params = {}) {
  1993. return passthrough('closeWindow', params);
  1994. }
  1995. /**
  1996. * 批量隐藏功能按钮。
  1997. *
  1998. * @note
  1999. * 完整功能按钮列表请参考[所有菜单项列表](#14926)。
  2000. *
  2001. * @example
  2002. * ```ts
  2003. * ww.hideMenuItems({
  2004. * menuList: ['menuItem:setFont']
  2005. * })
  2006. * ```
  2007. */ function hideMenuItems(params) {
  2008. return passthrough('hideMenuItems', params);
  2009. }
  2010. /**
  2011. * 批量显示功能按钮。
  2012. *
  2013. * @note
  2014. * 完整功能按钮列表请参考[所有菜单项列表](#14926)。
  2015. *
  2016. * @example
  2017. * ```ts
  2018. * ww.showMenuItems({
  2019. * menuList: ['menuItem:setFont']
  2020. * })
  2021. * ```
  2022. */ function showMenuItems(params) {
  2023. return passthrough('showMenuItems', params);
  2024. }
  2025. /**
  2026. * 隐藏所有非基础按钮。
  2027. *
  2028. * @example
  2029. * ```ts
  2030. * ww.hideAllNonBaseMenuItem()
  2031. * ```
  2032. */ function hideAllNonBaseMenuItem(params = {}) {
  2033. return passthrough('hideAllNonBaseMenuItem', params);
  2034. }
  2035. /**
  2036. * 显示所有功能按钮。
  2037. *
  2038. * @example
  2039. * ```ts
  2040. * ww.showAllNonBaseMenuItem()
  2041. * ```
  2042. */ function showAllNonBaseMenuItem(params = {}) {
  2043. return passthrough('showAllNonBaseMenuItem', params);
  2044. }
  2045. /**
  2046. * 使用系统浏览器打开指定 URL,支持传入 oauth2 链接,从而实现在系统浏览器内免登录的效果。
  2047. *
  2048. * @compat WeCom PC >= 2.3.0
  2049. *
  2050. * @example
  2051. * ```ts
  2052. * ww.openDefaultBrowser({
  2053. * url: 'https://work.weixin.qq.com/'
  2054. * })
  2055. * ```
  2056. */ function openDefaultBrowser(params) {
  2057. return passthrough('openDefaultBrowser', params);
  2058. }
  2059. /**
  2060. * 监听用户截屏事件。
  2061. *
  2062. * @compat WeCom iOS, Android >= 2.5.0
  2063. *
  2064. * @example
  2065. * ```ts
  2066. * ww.onUserCaptureScreen(function() {
  2067. * console.log('用户截屏了')
  2068. * })
  2069. * ```
  2070. */ function onUserCaptureScreen(callback) {
  2071. on('onUserCaptureScreen', callback);
  2072. }
  2073. /**
  2074. * 获取「转发」按钮点击状态并自定义分享内容。
  2075. *
  2076. * @note
  2077. * 微信客户端即将废弃该接口。
  2078. *
  2079. * @limit
  2080. * - 仅激活成员数超过 200 人且已经认证的企业才可在微信上调用
  2081. *
  2082. * @example
  2083. * ```ts
  2084. * ww.onMenuShareAppMessage({
  2085. * title: '企业微信',
  2086. * desc: '让每个企业都有自己的微信',
  2087. * link: 'https://work.weixin.qq.com/',
  2088. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png',
  2089. * success() {
  2090. * // 用户确认分享后回调
  2091. * },
  2092. * cancel() {
  2093. * // 用户取消分享后回调
  2094. * }
  2095. * })
  2096. * ```
  2097. */ function onMenuShareAppMessage(params) {
  2098. bindShare('menu:share:appmessage', params, ()=>invoke('sendAppMessage', {
  2099. title: params.title || getTitle(),
  2100. desc: params.desc || '',
  2101. link: params.link || getHref(),
  2102. img_url: params.imgUrl || '',
  2103. type: params.type || 'link',
  2104. data_url: params.dataUrl || '',
  2105. finder_feed: params.finderFeed || params.finder_feed,
  2106. finder_topic: params.finderTopic || params.finder_topic,
  2107. finder_profile: params.finderProfile || params.finder_profile,
  2108. enableIdTrans: params.enableIdTrans ? 1 : 0
  2109. }));
  2110. }
  2111. /**
  2112. * 获取「分享到朋友圈」按钮点击状态并自定义分享内容。
  2113. *
  2114. * @note
  2115. * 微信客户端即将废弃该接口。
  2116. *
  2117. * @example
  2118. * ```ts
  2119. * ww.onMenuShareTimeline({
  2120. * title: '企业微信',
  2121. * link: 'https://work.weixin.qq.com/',
  2122. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png',
  2123. * success() {
  2124. * // 用户确认分享后回调
  2125. * },
  2126. * cancel() {
  2127. * // 用户取消分享后回调
  2128. * }
  2129. * })
  2130. * ```
  2131. */ function onMenuShareTimeline(params) {
  2132. bindShare('menu:share:timeline', params, ()=>invoke('shareTimeline', {
  2133. title: params.title || getTitle(),
  2134. desc: params.title || getTitle(),
  2135. img_url: params.imgUrl || '',
  2136. link: params.link || getHref(),
  2137. type: params.type || 'link',
  2138. data_url: params.dataUrl || '',
  2139. enableIdTrans: params.enableIdTrans ? 1 : 0
  2140. }));
  2141. }
  2142. /**
  2143. * 获取「微信」按钮点击状态并自定义分享内容。
  2144. *
  2145. * @compat WeCom
  2146. *
  2147. * @example
  2148. * ```ts
  2149. * ww.onMenuShareWechat({
  2150. * title: '企业微信',
  2151. * desc: '让每个企业都有自己的微信',
  2152. * link: 'https://work.weixin.qq.com/',
  2153. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png',
  2154. * success() {
  2155. * // 用户确认分享后回调
  2156. * },
  2157. * cancel() {
  2158. * // 用户取消分享后回调
  2159. * }
  2160. * })
  2161. * ```
  2162. */ function onMenuShareWechat(params) {
  2163. bindShare('menu:share:wechat', params, ()=>invoke('shareWechat', {
  2164. title: params.title || getTitle(),
  2165. desc: params.desc || '',
  2166. link: params.link || getHref(),
  2167. img_url: params.imgUrl || '',
  2168. type: params.type || 'link',
  2169. data_url: params.dataUrl || '',
  2170. enableIdTrans: params.enableIdTrans ? 1 : 0
  2171. }));
  2172. }
  2173. /**
  2174. * 获取「分享到QQ」按钮点击状态并自定义分享内容。
  2175. *
  2176. * @note
  2177. * 微信客户端即将废弃该接口。
  2178. *
  2179. * @compat WeChat
  2180. */ function onMenuShareQQ(params) {
  2181. bindShare('menu:share:qq', params, ()=>invoke('shareQQ', {
  2182. title: params.title || getTitle(),
  2183. desc: params.desc || '',
  2184. img_url: params.imgUrl || '',
  2185. link: params.link || getHref()
  2186. }));
  2187. }
  2188. /**
  2189. * 获取「分享到微博」按钮点击状态并自定义分享内容。
  2190. *
  2191. * @compat WeChat
  2192. */ function onMenuShareWeibo(params) {
  2193. bindShare('menu:share:weiboApp', params, ()=>invoke('shareWeiboApp', {
  2194. title: params.title || getTitle(),
  2195. desc: params.desc || '',
  2196. img_url: params.imgUrl || '',
  2197. link: params.link || getHref()
  2198. }));
  2199. }
  2200. /**
  2201. * 获取「分享到QQ空间」按钮点击状态并自定义分享内容。
  2202. *
  2203. * @note
  2204. * 微信客户端即将废弃该接口。
  2205. *
  2206. * @compat WeChat
  2207. */ function onMenuShareQZone(params) {
  2208. bindShare('menu:share:QZone', params, ()=>invoke('shareQZone', {
  2209. title: params.title || getTitle(),
  2210. desc: params.desc || '',
  2211. img_url: params.imgUrl || '',
  2212. link: params.link || getHref()
  2213. }));
  2214. }
  2215. /**
  2216. * 自定义转发到会话。
  2217. *
  2218. * @compat WeCom >= 2.4.5
  2219. *
  2220. * @example
  2221. * ```ts
  2222. * ww.shareAppMessage({
  2223. * title: '企业微信',
  2224. * desc: '让每个企业都有自己的微信',
  2225. * link: 'https://work.weixin.qq.com/',
  2226. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png',
  2227. * })
  2228. * ```
  2229. */ function shareAppMessage(params) {
  2230. return passthrough('shareAppMessage', params);
  2231. }
  2232. /**
  2233. * 自定义转发到微信。
  2234. *
  2235. * @compat WeCom >= 2.4.5
  2236. *
  2237. * @example
  2238. * ```ts
  2239. * ww.shareWechatMessage({
  2240. * title: '企业微信',
  2241. * desc: '让每个企业都有自己的微信',
  2242. * link: 'https://work.weixin.qq.com/',
  2243. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png',
  2244. * })
  2245. * ```
  2246. */ function shareWechatMessage(params) {
  2247. return passthrough('shareWechatMessage', params);
  2248. }
  2249. /**
  2250. * 自定义「分享到朋友圈」及「分享到QQ空间」按钮的分享内容。
  2251. *
  2252. * @compat WeChat
  2253. */ function updateTimelineShareData(params = {}) {
  2254. return passthrough('updateTimelineShareData', params);
  2255. }
  2256. /**
  2257. * 自定义「分享给朋友」及「分享到QQ」按钮的分享内容。
  2258. *
  2259. * @compat WeChat
  2260. */ function updateAppMessageShareData(params = {}) {
  2261. return passthrough('updateAppMessageShareData', params);
  2262. }
  2263. /**
  2264. * 批量添加卡券。
  2265. *
  2266. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#批量添加卡券接口
  2267. */ function addCard(params) {
  2268. return promiseToCallback(params, async ()=>{
  2269. await tryEnsureConfigReady();
  2270. const res = await invoke('batchAddCard', {
  2271. card_list: params.cardList.map((card)=>({
  2272. card_id: card.cardId,
  2273. card_ext: card.cardExt
  2274. }))
  2275. });
  2276. if (!res.card_list) {
  2277. return res;
  2278. }
  2279. for (const card of res.card_list){
  2280. card.cardId = card.card_id;
  2281. delete card.card_id;
  2282. card.cardExt = card.card_ext;
  2283. delete card.card_ext;
  2284. card.isSuccess = !!card.is_succ;
  2285. delete card.is_succ;
  2286. }
  2287. res.cardList = res.card_list;
  2288. delete res.card_list;
  2289. return res;
  2290. });
  2291. }
  2292. /**
  2293. * 拉取适用卡券列表并获取用户选择信息。
  2294. *
  2295. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#拉取适用卡券列表并获取用户选择信息
  2296. */ function chooseCard(params) {
  2297. return promiseToCallback(params, async ()=>{
  2298. await tryEnsureConfigReady();
  2299. const res = await invoke('chooseCard', {
  2300. app_id: getConfigCorpId(),
  2301. location_id: params.shopId || '',
  2302. sign_type: params.signType || 'SHA1',
  2303. card_id: params.cardId || '',
  2304. card_type: params.cardType || '',
  2305. card_sign: params.cardSign,
  2306. time_stamp: `${params.timestamp}`,
  2307. nonce_str: params.nonceStr
  2308. });
  2309. res.cardList = res.choose_card_info;
  2310. delete res.choose_card_info;
  2311. return res;
  2312. });
  2313. }
  2314. /**
  2315. * 查看微信卡包中的卡券。
  2316. *
  2317. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#查看微信卡包中的卡券接口
  2318. */ function openCard(params) {
  2319. return passthrough('batchViewCard', params, {
  2320. card_list: params.cardList.map((card)=>({
  2321. card_id: card.cardId,
  2322. code: card.code
  2323. }))
  2324. });
  2325. }
  2326. /**
  2327. * 核销并分享卡券。
  2328. *
  2329. * @deprecated
  2330. */ function consumeAndShareCard(params) {
  2331. return passthrough('consumedShareCard', params, {
  2332. consumedCardId: params.cardId,
  2333. consumedCode: params.code
  2334. });
  2335. }
  2336. exports.ProductViewType = void 0;
  2337. (function(ProductViewType) {
  2338. ProductViewType[ProductViewType["normal"] = 0] = "normal";
  2339. ProductViewType[ProductViewType["scan"] = 1] = "scan";
  2340. })(exports.ProductViewType || (exports.ProductViewType = {}));
  2341. /**
  2342. * 跳转微信商品页。
  2343. *
  2344. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#跳转微信商品页接口
  2345. */ function openProductSpecificView(params) {
  2346. return passthrough('openProductViewWithPid', params, {
  2347. pid: params.productId,
  2348. view_type: params.viewType || 0,
  2349. ext_info: params.extInfo
  2350. });
  2351. }
  2352. /**
  2353. * 发起一个微信支付请求。
  2354. *
  2355. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#发起一个微信支付请求
  2356. */ function chooseWXPay(params) {
  2357. return passthrough('getBrandWCPayRequest', params, normalizeParams(params));
  2358. }
  2359. /**
  2360. * 领取企业红包。
  2361. */ function openEnterpriseRedPacket(params) {
  2362. return passthrough('getRecevieBizHongBaoRequest', params, normalizeParams(params));
  2363. }
  2364. function normalizeParams(params) {
  2365. return {
  2366. timeStamp: `${params.timestamp}`,
  2367. nonceStr: params.nonceStr,
  2368. package: params.package,
  2369. paySign: params.paySign,
  2370. signType: params.signType || 'SHA1'
  2371. };
  2372. }
  2373. /**
  2374. * 添加设备。
  2375. *
  2376. * @limit
  2377. * - 本接口必须使用应用身份进行注册
  2378. * - 发起用户需要有设备添加权限(超级管理员/设备管理员)
  2379. *
  2380. * @compat WeCom iOS, Android >= 4.0.18
  2381. *
  2382. * @example
  2383. * ```ts
  2384. * ww.addDevice({
  2385. * type: 'qrcode',
  2386. * qrcode_url: 'https://open.work.weixin.qq.com/connect?xxx',
  2387. * })
  2388. * ```
  2389. */ function addDevice(params) {
  2390. return passthrough('addDevice', params);
  2391. }
  2392. /**
  2393. * 判断当前客户端版本是否支持指定 JS 接口。
  2394. *
  2395. * @example
  2396. * ```ts
  2397. * ww.checkJsApi({
  2398. * jsApiList: ['chooseImage']
  2399. * })
  2400. * ```
  2401. */ async function checkJsApi(params) {
  2402. return promiseToCallback(params, async ()=>{
  2403. await tryEnsureConfigReady();
  2404. const res = await invoke('checkJsApi', {
  2405. jsApiList: mapJsApiListToClient(params.jsApiList)
  2406. });
  2407. if (typeof res.checkResult === 'string') {
  2408. try {
  2409. res.checkResult = JSON.parse(res.checkResult);
  2410. } catch (error) {
  2411. res.checkResult = {};
  2412. }
  2413. }
  2414. res.checkResult = normalize(flatten(res.checkResult));
  2415. return res;
  2416. });
  2417. }
  2418. function normalize(data) {
  2419. const result = {
  2420. ...data
  2421. };
  2422. for (const key of Object.keys(data)){
  2423. result[mapJsApiNameToWeb(key)] = data[key];
  2424. }
  2425. return result;
  2426. }
  2427. function flatten(data) {
  2428. const result = {};
  2429. for (const key of Object.keys(data)){
  2430. if (!isObject$1(data[key])) {
  2431. result[key] = data[key];
  2432. continue;
  2433. }
  2434. const child = flatten(data[key]);
  2435. for (const childKey of Object.keys(child)){
  2436. result[`${key}.${childKey}`] = child[childKey];
  2437. }
  2438. }
  2439. return result;
  2440. }
  2441. /**
  2442. * 查看其他成员某段时间内日程中的闲忙状态。
  2443. *
  2444. * @limit
  2445. * - 本接口必须使用应用身份进行注册
  2446. * - 当前成员必须在应用可见范围内
  2447. * - 应用需具有日程使用权限
  2448. *
  2449. * @compat WeCom >= 4.0.20
  2450. *
  2451. * @example
  2452. * ```ts
  2453. * ww.checkSchedule({
  2454. * start_time: 1667232000,
  2455. * end_time: 1667318400,
  2456. * users: ['jack', 'jason']
  2457. * })
  2458. * ```
  2459. */ function checkSchedule(params) {
  2460. return passthrough('checkSchedule', params);
  2461. }
  2462. /**
  2463. * 拉起电子发票列表。
  2464. *
  2465. * @compat WeCom iOS, Android >= 2.1.0
  2466. *
  2467. * @example
  2468. * ```ts
  2469. * ww.chooseInvoice({
  2470. * timestamp: timestamp,
  2471. * nonceStr: nonceStr,
  2472. * signType: signType,
  2473. * cardSign: cardSign
  2474. * })
  2475. * ```
  2476. *
  2477. * @throws
  2478. * | errMsg | 说明 |
  2479. * | --- | --- |
  2480. * | choose_invoice:ok | 执行成功 |
  2481. * | choose_invoice: fail | 选取发票失败 |
  2482. * | choose_invoice: cancel | 选取发票取消 |
  2483. */ function chooseInvoice(params) {
  2484. return passthrough('chooseInvoice', params);
  2485. }
  2486. /**
  2487. * 跳转到认领班级的界面。
  2488. *
  2489. * @compat WeCom >= 3.1.8
  2490. *
  2491. * @limit 本接口必须使用应用身份进行注册
  2492. *
  2493. * @example
  2494. * ```ts
  2495. * ww.claimClassAdmin()
  2496. * ```
  2497. *
  2498. * @throws
  2499. * | errMsg | 说明 |
  2500. * | --- | --- |
  2501. * | claimClassAdmin:ok | 执行成功 |
  2502. * | claimClassAdmin:fail no permission | 应用身份鉴权失败 |
  2503. * | claimClassAdmin:fail user not in allow list | 当前成员不在应用可见范围 |
  2504. */ function claimClassAdmin(params = {}) {
  2505. return passthrough('claimClassAdmin', params);
  2506. }
  2507. /**
  2508. * 向用户申请给指定范围发送消息。
  2509. *
  2510. * 调用接口后,用户可在选人界面对群聊范围进行修改,当创建群聊成功时会返回新建的群聊 ID。
  2511. *
  2512. * @limit
  2513. * - 仅第三方应用(非通讯录应用)与代开发应用可调用
  2514. * - 本接口必须使用应用身份进行注册
  2515. *
  2516. * @compat WeCom >= 3.1.8
  2517. *
  2518. * @example
  2519. * ```ts
  2520. * ww.createChatWithMsg({
  2521. * selectedOpenUserIds: ['zhangsan','lisi'],
  2522. * selectedTickets: ['tick1','token2'],
  2523. * chatName: 'discussName',
  2524. * msg: {
  2525. * msgtype: 'link',
  2526. * link: {
  2527. * title: 'title1',
  2528. * desc: 'desc1',
  2529. * url: 'link1',
  2530. * imgUrl: 'imgurl1'
  2531. * }
  2532. * }
  2533. * })
  2534. * ```
  2535. *
  2536. * @throws
  2537. * | errMsg | 说明 |
  2538. * | --- | --- |
  2539. * | createChatWithMsg:ok | 执行成功 |
  2540. * | createChatWithMsg:fail_unsupported_msgtype | msgtype不合法 |
  2541. * | createChatWithMsg:fail_msg_link_missing_url | msg.link.url未传入 |
  2542. */ function createChatWithMsg(params) {
  2543. return passthrough('createChatWithMsg', params);
  2544. }
  2545. /**
  2546. * 创建企业互联/上下游会话。
  2547. *
  2548. * @limit
  2549. * - 本接口必须使用应用身份进行注册
  2550. * - 企业必须开启互联群功能
  2551. * - 仅局校互联和上下游企业可调用
  2552. * - 当前成员必须在应用的可见范围
  2553. * - 群成员人数不能超过 2000 人
  2554. * - 如果创建的会话有外部联系人,群成员人数不能超过 40 人
  2555. * - 当前成员为下游企业成员时,需要打开上下游空间中的“允许外部单位之间互相查看”配置,群成员中才可以包含其他下游企业成员
  2556. *
  2557. * @compat WeCom iOS, Android, PC >= 3.1.8
  2558. *
  2559. * @example
  2560. * ```ts
  2561. * ww.createCorpGroupChat({
  2562. * groupName: '讨论组',
  2563. * userIds: ['lisi', 'lisi2'],
  2564. * openUserIds: ['wabc3', 'wbcde'],
  2565. * externalUserIds: ['exid1', 'exid2'],
  2566. * corpGroupUserIds: [
  2567. * {
  2568. * corpId: 'ww3333',
  2569. * userId: 'userid123',
  2570. * openUserId: 'wx1111'
  2571. * },
  2572. * {
  2573. * corpId: 'ww4444',
  2574. * userId: 'userid123',
  2575. * openUserId: 'wx1111'
  2576. * }
  2577. * ]
  2578. * })
  2579. * ```
  2580. *
  2581. * @throws
  2582. * | errMsg | 说明 |
  2583. * | --- | --- |
  2584. * | createCorpGroupChat:ok | 执行成功 |
  2585. * | createCorpGroupChat:fail no permission | 应用签名校验失败 |
  2586. * | createCorpGroupChat:fail exceed user id list size | 超过人数上限 |
  2587. * | createCorpGroupChat:fail invalid parameter | 参数不合法 |
  2588. * | createCorpGroupChat:fail need open corp group chat | 企业未开启企业互联群功能 |
  2589. * | createCorpGroupChat:fail exceed external user id list size | 超过包含外部联系人群人数上限 |
  2590. */ function createCorpGroupChat(params) {
  2591. return passthrough('createCorpGroupChat', params, {
  2592. groupName: params.groupName || '',
  2593. userIds: params.userIds,
  2594. openUserIds: params.openUserIds,
  2595. externalUserIds: params.externalUserIds,
  2596. corpGroupUserIds: params.corpGroupUserIds
  2597. });
  2598. }
  2599. exports.CreateExternalPaymentType = void 0;
  2600. (function(CreateExternalPaymentType) {
  2601. /**
  2602. * 在聊天中收款
  2603. */ CreateExternalPaymentType[CreateExternalPaymentType["chat"] = 0] = "chat";
  2604. /**
  2605. * 收款码收款
  2606. */ CreateExternalPaymentType[CreateExternalPaymentType["qrcode"] = 1] = "qrcode";
  2607. })(exports.CreateExternalPaymentType || (exports.CreateExternalPaymentType = {}));
  2608. /**
  2609. * 发起对外收款。
  2610. *
  2611. * @limit
  2612. * - 本接口必须使用应用身份进行注册
  2613. * - 所使用的应用必须具有对外收款权限
  2614. * - 发起的用户必须在应用可见范围并实名
  2615. * - 允许第三方应用、代开发应用和自建应用调用
  2616. *
  2617. * @compat WeCom >= 4.0.12
  2618. *
  2619. * @example
  2620. * ```ts
  2621. * ww.createExternalPayment({
  2622. * paymentType: 0,
  2623. * totalFee: 300,
  2624. * description: '可乐一罐'
  2625. * })
  2626. * ```
  2627. */ function createExternalPayment(params = {}) {
  2628. return passthrough('createExternalPayment', params);
  2629. }
  2630. /**
  2631. * 发起班级收款。
  2632. *
  2633. * 用于老师对学生家长发起付款请求,接口调用成功后会通过家校通知发送付款小程序给家长。
  2634. *
  2635. * @limit
  2636. * - 本接口必须使用应用身份进行注册
  2637. * - 所使用的应用必须具有对外收款权限
  2638. * - 仅支持配置在家长可使用范围内的应用
  2639. * - 企业必须已验证或者已认证
  2640. * - 发起的用户必须在应用可见范围并实名
  2641. * - 发起的用户需在个人微信零钱账户的可用范围内
  2642. *
  2643. * @compat WeCom iOS, Android, PC >= 3.1.10
  2644. *
  2645. * @note
  2646. * - 用户可以手动调整收款金额,收款项目和收款范围
  2647. * - 通过接口发起的收款,默认收款账户为“我的微信零钱账户”,且不可修改
  2648. * - 若用户未授权个人付款码权限,会唤起授权付款码权限页面,授权完成返回页面后会返回错误信息 `'require authorize the payment qr code'`。用户授权完成后可引导用户重新发起收款
  2649. *
  2650. * @example
  2651. * ```ts
  2652. * ww.createSchoolPayment({
  2653. * projectName: '1班班费',
  2654. * amount: 100,
  2655. * payers: {
  2656. * students: ['zhagnshan', 'lisi'],
  2657. * departments: [1, 2]
  2658. * }
  2659. * })
  2660. * ```
  2661. */ function createSchoolPayment(params) {
  2662. return passthrough('createSchoolPayment', params);
  2663. }
  2664. /**
  2665. * 添加设备。
  2666. *
  2667. * @deprecated 请使用 addDevice 接口
  2668. *
  2669. * @limit
  2670. * 调用者必须为企业超级管理员
  2671. *
  2672. * @compat WeCom iOS, Android >= 2.5.8
  2673. *
  2674. * @example
  2675. * ```ts
  2676. * ww.discoverDevice({
  2677. * type: 'qrcode',
  2678. * qrcode_url: 'https://open.work.weixin.qq.com/connect?xxx'
  2679. * })
  2680. * ```
  2681. */ function discoverDevice(params) {
  2682. return passthrough('discoverDevice', params);
  2683. }
  2684. /**
  2685. * 加入视频会议。
  2686. *
  2687. * @limit
  2688. * 只能加入同企业硬件创建的视频会议。
  2689. *
  2690. * @compat WeCom >= 2.5.0
  2691. *
  2692. * @example
  2693. * ```ts
  2694. * ww.enterHWOpenTalk({
  2695. * code: code,
  2696. * ticket: ticket
  2697. * })
  2698. * ```
  2699. */ function enterHWOpenTalk(params) {
  2700. return passthrough('enterHWOpenTalk', params);
  2701. }
  2702. /**
  2703. * 跳转认证界面。
  2704. *
  2705. * @compat WeCom iOS, Android >= 2.8.7
  2706. *
  2707. * @example
  2708. * ```ts
  2709. * ww.enterpriseVerify()
  2710. * ```
  2711. */ function enterpriseVerify(params = {}) {
  2712. return passthrough('enterpriseVerify', params);
  2713. }
  2714. /**
  2715. * 获取 saveApprovalSelectedItems 保存的审批选项。
  2716. *
  2717. * 当用户打开网页后,应该先调用一次该接口获取用户已经选择的数据作为初始数据。获取到初始数据后,应该恢复已经选择的选项。
  2718. *
  2719. * @limit
  2720. * - 本接口必须使用应用身份进行注册
  2721. * - 所签名的应用必须具有审批权限
  2722. *
  2723. * @note
  2724. * - 网页应该做好深色模式适配
  2725. * - 接口仅用于审批设置外部选项场景,请勿用作其他场景
  2726. *
  2727. * @compat WeCom >= 4.0.18
  2728. *
  2729. * @example
  2730. * ```ts
  2731. * ww.getApprovalSelectedItems({
  2732. * key: 'key'
  2733. * })
  2734. * ```
  2735. */ function getApprovalSelectedItems(params) {
  2736. return promiseToCallback(params, async ()=>{
  2737. await tryEnsureConfigReady();
  2738. const res = await invoke('getApprovalSelectedItems', {
  2739. key: params.key
  2740. });
  2741. if (!res.selectedData) {
  2742. return res;
  2743. }
  2744. try {
  2745. res.selectedData = JSON.parse(res.selectedData);
  2746. } catch (error) {
  2747. res.selectedData = [];
  2748. }
  2749. return res;
  2750. });
  2751. }
  2752. exports.EntryType = void 0;
  2753. (function(EntryType) {
  2754. /**
  2755. * 从联系人详情进入
  2756. */ EntryType["contact_profile"] = "contact_profile";
  2757. /**
  2758. * 从单聊会话的工具栏进入
  2759. */ EntryType["single_chat_tools"] = "single_chat_tools";
  2760. /**
  2761. * 从群聊会话的工具栏进入
  2762. */ EntryType["group_chat_tools"] = "group_chat_tools";
  2763. /**
  2764. * 从会话的聊天附件栏进入
  2765. *
  2766. * @compat WeCom >= 3.1.6
  2767. */ EntryType["chat_attachment"] = "chat_attachment";
  2768. /**
  2769. * 从微信客服的工具栏进入
  2770. *
  2771. * @compat WeCom >= 3.1.10
  2772. */ EntryType["single_kf_tools"] = "single_kf_tools";
  2773. /**
  2774. * 上下游单聊会话的工具栏
  2775. *
  2776. * @compat WeCom >= 4.0.8
  2777. */ EntryType["chain_single_chat_tools"] = "chain_single_chat_tools";
  2778. /**
  2779. * 上下游群聊会话的工具栏
  2780. *
  2781. * @compat WeCom >= 4.0.8
  2782. */ EntryType["chain_group_chat_tools"] = "chain_group_chat_tools";
  2783. /**
  2784. * 从内部群群看板进入
  2785. *
  2786. * @compat WeCom >= 4.1.36
  2787. */ EntryType["internal_group_chat_board"] = "internal_group_chat_board";
  2788. /**
  2789. * 除以上场景之外进入,例如工作台,聊天会话等
  2790. */ EntryType["normal"] = "normal";
  2791. })(exports.EntryType || (exports.EntryType = {}));
  2792. /**
  2793. * 获取当前页面打开场景。
  2794. *
  2795. * @note
  2796. * 调用该接口可以判断用户是从哪个入口打开页面,从而决定是否可以调用客户联系相关的接口。
  2797. *
  2798. * @compat WeCom >= 3.0.24
  2799. *
  2800. * @example
  2801. * ```ts
  2802. * ww.getContext()
  2803. * ```
  2804. */ function getContext(params = {}) {
  2805. return passthrough('getContext', params);
  2806. }
  2807. /**
  2808. * 页面在聊天工具栏中打开时,获取当前上下游互联群的群 ID.
  2809. *
  2810. * @compat WeCom >= 4.0.12
  2811. *
  2812. * @limit
  2813. * - 仅支持上下游聊天工具栏中进入的页面调用,即 getContext 返回 `entry` 为 `chain_single_chat_tools` 或 `chain_group_chat_tools` 的场景
  2814. * - 本接口必须使用应用身份进行注册
  2815. * - 当前成员必须在应用的可见范围
  2816. *
  2817. * @example
  2818. * ```
  2819. * ww.getCurCorpGroupChat()
  2820. * ```
  2821. * @throws
  2822. * | errMsg | 说明 |
  2823. * | --- | --- |
  2824. * | getCurCorpGroupChat:ok| 执行成功 |
  2825. * | getCurCorpGroupChat:no permission | 应用身份鉴权失败 |
  2826. * | getCurCorpGroupChat:without context of corpgroup contact | 当前页面入口不支持调用 |
  2827. */ function getCurCorpGroupChat(params = {}) {
  2828. return passthrough('getCurCorpGroupChat', params);
  2829. }
  2830. /**
  2831. * 页面在上下游聊天工具栏中打开时,获取当前上下游联系人用户 ID。
  2832. *
  2833. * @compat WeCom >= 4.0.8
  2834. *
  2835. * @limit
  2836. * - 仅支持上下游聊天工具栏中进入的页面调用,即 getContext 返回 `entry` 为 `chain_single_chat_tools` 或 `chain_group_chat_tools` 的场景
  2837. * - 本接口必须使用应用身份进行注册
  2838. * - 当前成员必须在应用的可见范围
  2839. *
  2840. * @example
  2841. * ```
  2842. * ww.getCurCorpGroupContact()
  2843. * ```
  2844. * @throws
  2845. * | errMsg | 说明 |
  2846. * | --- | --- |
  2847. * | getCurCorpGroupContact:ok| 执行成功 |
  2848. * | getCurCorpGroupContact:no permission | 应用身份鉴权失败 |
  2849. * | getCurCorpGroupContact:without context of corpgroup contact | 当前页面入口不支持调用 |
  2850. */ function getCurCorpGroupContact(params) {
  2851. return passthrough('getCurCorpGroupContact', params);
  2852. }
  2853. /**
  2854. * 获取当前客户群的群 ID。
  2855. *
  2856. * @limit
  2857. * - 本接口必须使用应用身份进行注册
  2858. * - 从客户群或班级群的聊天工具栏进入页面时才可成功调用该接口
  2859. * - 不同的入口对应用及用户有相应的限制
  2860. * | 入口 | getContext 接口返回的 entry 值 | 自建应用 | 第三方应用 | 用户 | 兼容性 |
  2861. * | --- | --- | --- | --- | --- | --- |
  2862. * | 外部群聊工具栏 | group_chat_tools | 需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用) | 需有“企业客户权限->客户基础信息”权限 | 配置了[客户联系功能](#13473/配置可使用客户联系功能的成员) | 企业微信 2.8.17 |
  2863. * | 班级群的聊天工具栏 | group_chat_tools | 所有 | 需有「家校沟通」使用权限 | 所有 | 企业微信 3.0.36 |
  2864. * | 学生群的聊天工具栏 | group_chat_tools | 所有 | 需有「家校沟通」使用权限 | 所有 | 企业微信 4.0.8 |
  2865. *
  2866. * @compat WeCom >= 2.8.17
  2867. *
  2868. * @example
  2869. * ```ts
  2870. * ww.getCurExternalChat()
  2871. * ```
  2872. *
  2873. * @throws
  2874. * | errMsg | 说明 |
  2875. * | --- | --- |
  2876. * | getCurExternalChat:ok | 执行成功 |
  2877. * | getCurExternalChat:fail no permission | 应用签名校验失败,或签名所使用的应用不满足权限要求 |
  2878. * | getCurExternalChat:fail without context of external contact | 当前页面入口不支持调用 |
  2879. */ function getCurExternalChat(params = {}) {
  2880. return passthrough('getCurExternalChat', params);
  2881. }
  2882. /**
  2883. * 获取当前外部联系人 userId。
  2884. *
  2885. * @limit
  2886. * - 本接口必须使用应用身份进行注册
  2887. * - 不同的入口对应用及用户有相应的限制,目前支持的入口有联系人详情页、外部单聊工具栏
  2888. * | getContext 接口返回的 entry 值 | 自建应用 | 第三方应用 | 用户 | 支持的最低版本 |
  2889. * | --- | --- | --- | --- | --- |
  2890. * | contact_profile | [客户联系功能权限](#13473/配置可使用客户联系接口的应用) | 需有“企业客户权限->客户基础信息”权限 | 配置了|[客户联系功能](#13473/配置可使用客户联系功能的成员) | 企业微信 2.5.8 |
  2891. * | single_chat_tools | [客户联系功能权限](#13473/配置可使用客户联系接口的应用) | 需有“企业客户权限->客户基础信息”权限 | 配置了|[客户联系功能](#13473/配置可使用客户联系功能的成员) | 企业微信 2.8.10 |
  2892. * | single_kf_tools | 所有 | 需有“微信客服权限->获取基础信息”权限 | 所有 | 企业微信 3.1.10 |
  2893. *
  2894. * @compat WeCom >= 2.5.8
  2895. *
  2896. * @example
  2897. * ```ts
  2898. * ww.getCurExternalContact()
  2899. * ```
  2900. *
  2901. * @throws
  2902. * | errMsg | 说明 |
  2903. * | --- | --- |
  2904. * | getCurExternalContact:ok | 执行成功 |
  2905. * | getCurExternalContact:fail no permission | 应用签名校验失败或应用不满足权限条件 |
  2906. * | getCurExternalContact:fail without context of external contact | 当前页面入口不支持调用 |
  2907. */ function getCurExternalContact(params = {}) {
  2908. return passthrough('getCurExternalContact', params);
  2909. }
  2910. /**
  2911. * 获取私密消息信息。
  2912. *
  2913. * @compat WeCom >= 3.1.8
  2914. *
  2915. * @limit
  2916. * 本接口必须使用应用身份进行注册
  2917. *
  2918. * @example
  2919. * ```ts
  2920. * ww.getShareInfo({
  2921. * shareTicket: 'xxx'
  2922. * })
  2923. * ```
  2924. */ function getShareInfo(params) {
  2925. return passthrough('getShareInfo', params);
  2926. }
  2927. /**
  2928. * 页面在聊天附件栏中打开时,隐藏聊天附件栏的发送按钮。开发者可以通过[分享消息到当前会话](#sendChatMessage)接口灵活适配对页面或页面中具体内容的转发。
  2929. *
  2930. * @limit
  2931. * - 仅支持聊天附件栏进入的页面调用,即 getContext 返回 `entry` 为 `chat_attachment` 的场景
  2932. * - 本接口必须使用应用身份进行注册
  2933. *
  2934. * @compat WeCom >= 3.1.6
  2935. *
  2936. * @example
  2937. * ```
  2938. * ww.hideChatAttachmentMenu({
  2939. * menuList: ["sendMessage"]
  2940. * })
  2941. * ```
  2942. *
  2943. * @throws
  2944. * | errMsg | 说明 |
  2945. * | --- | --- |
  2946. * | hideChatAttachmentMenu:ok | 执行成功 |
  2947. * | hideChatAttachmentMenu:invalid menuList | menuList不合法 |
  2948. * | hideChatAttachmentMenu:without context of chat_attachment | 未在聊天附件栏打开场景下调用 |
  2949. */ function hideChatAttachmentMenu(params) {
  2950. return passthrough('hideChatAttachmentMenu', params);
  2951. }
  2952. /**
  2953. * 跳转到小程序。
  2954. *
  2955. * @note
  2956. * 打开小程序时如果需要关闭页面,需同步调用 closeWindow,不推荐用 setTimeout 延迟关闭。
  2957. *
  2958. * @limit
  2959. * - 本接口必须使用应用身份进行注册
  2960. * - 跳转的小程序必须属于页面所属的企业
  2961. * - 跳转的小程序必须已关联到工作台
  2962. * - 应用必须与要跳转的小程序应用同属于一个企业
  2963. * - 跳转的小程序必须已经关联到工作台
  2964. *
  2965. * @compat WeCom >= 3.0.36
  2966. *
  2967. * @example
  2968. * ```ts
  2969. * ww.launchMiniprogram({
  2970. * appid: 'wx062f7a5507909000',
  2971. * path: 'pages/home/index'
  2972. * })
  2973. * ```
  2974. */ function launchMiniprogram(params) {
  2975. return passthrough('launchMiniprogram', params, {
  2976. appid: params.appid,
  2977. path: addHTMLToPath(params.path),
  2978. envVersion: params.envVersion
  2979. });
  2980. }
  2981. function addHTMLToPath(url) {
  2982. if (!url || !isString(url)) {
  2983. return;
  2984. }
  2985. const [path, ...query] = url.split('?');
  2986. if (!query.length) {
  2987. return `${path}.html`;
  2988. }
  2989. return `${path}.html?${query.join('?')}`;
  2990. }
  2991. /**
  2992. * 在企业微信内快速跳转到添加客户的界面。
  2993. *
  2994. * @limit
  2995. * - 本接口必须使用应用身份进行注册
  2996. * - 应用需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用)
  2997. * - 当前成员必须配置了客户联系功能
  2998. *
  2999. * @compat WeCom iOS, Android >= 3.0.36
  3000. *
  3001. * @example
  3002. * ```ts
  3003. * ww.navigateToAddCustomer()
  3004. * ```
  3005. */ function navigateToAddCustomer(params = {}) {
  3006. return passthrough('navigateToAddCustomer', params);
  3007. }
  3008. /**
  3009. * 进入微信客服消息界面。
  3010. *
  3011. * @limit
  3012. * - 本接口必须使用应用身份进行注册
  3013. * - 应用必须具有“微信客服->获取基础信息”权限
  3014. * - 当前企业须已开启「微信客服」应用
  3015. * - 当前成员须是指定客服账号的坐席
  3016. *
  3017. * @compat WeCom iOS, Android, PC >= 3.1.12
  3018. *
  3019. * @example
  3020. * ```ts
  3021. * ww.navigateToKfChat({
  3022. * openKfId: 'wkAJ2GCAAAZSfhHCt7IFSvLKtMPxyAAA',
  3023. * externalUserId: 'wmAJ2GCAAAZSfhHCt7IFSvLKtMPxyBBB'
  3024. * })
  3025. * ```
  3026. */ function navigateToKfChat(params) {
  3027. return passthrough('navigateToKfChat', params);
  3028. }
  3029. /**
  3030. * 共享收货地址。
  3031. *
  3032. * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#共享收货地址接口
  3033. */ function openAddress(params = {}) {
  3034. return promiseToCallback(params, async ()=>{
  3035. await tryEnsureConfigReady();
  3036. const res = await invoke('editAddress');
  3037. res.postalCode = res.addressPostalCode;
  3038. delete res.addressPostalCode;
  3039. res.provinceName = res.proviceFirstStageName;
  3040. delete res.proviceFirstStageName;
  3041. res.cityName = res.addressCitySecondStageName;
  3042. delete res.addressCitySecondStageName;
  3043. res.countryName = res.addressCountiesThirdStageName;
  3044. delete res.addressCountiesThirdStageName;
  3045. res.detailInfo = res.addressDetailInfo;
  3046. delete res.addressDetailInfo;
  3047. return res;
  3048. });
  3049. }
  3050. /**
  3051. * 打开应用评价页面。
  3052. *
  3053. * 第三方应用可以使用该接口提供按钮,让用户快速打开应用评价页面。
  3054. *
  3055. * @compat WeCom iOS, Android, PC >= 4.0.2
  3056. *
  3057. * @limit
  3058. * - 本接口必须使用应用身份进行注册,
  3059. * - 仅第三方应用可调用
  3060. * - 对成员授权的应用,当前用户在应用可见范围内,可以进行应用评价
  3061. * - 管理员授权的应用,当前用户在可见范围内,或者当前用户为超管或有应用管理权限的分管,可以进行应用评价
  3062. *
  3063. * @example
  3064. * ```
  3065. * ww.openAppComment()
  3066. * ```
  3067. *
  3068. * @throws
  3069. * | errMsg | 说明 |
  3070. * | --- | --- |
  3071. * | openAppComment:ok| 执行成功 |
  3072. * | openAppComment:fail:no permission | 调用人身份不符合 |
  3073. * | openAppComment:fail:unknown app | 应用信息获取失败 |
  3074. * | openAppComment:fail:unsupported app type | 应用类型不符合要求 |
  3075. * | openAppComment:fail | 其它错误 |
  3076. */ function openAppComment(params = {}) {
  3077. return passthrough('openAppComment', params);
  3078. }
  3079. /**
  3080. * 获取设备数据授权。
  3081. *
  3082. * 唤起设备选择列表,企业管理员选择设备后,应用可以通过云端接口获取到设备上报的数据。
  3083. *
  3084. * @limit
  3085. * - 本接口必须使用应用身份进行注册
  3086. * - 应用必须具有智慧硬件接口权限
  3087. * - 仅第三方应用使用
  3088. *
  3089. * @compat WeCom >= 4.0.12
  3090. *
  3091. * @example
  3092. * ```ts
  3093. * ww.openAppDeviceDataAuth()
  3094. * ```
  3095. */ function openAppDeviceDataAuth(params = {}) {
  3096. return passthrough('openAppDeviceDataAuth', params);
  3097. }
  3098. exports.OpenAppManagePageType = void 0;
  3099. (function(OpenAppManagePageType) {
  3100. /**
  3101. * 应用权限详情页
  3102. */ OpenAppManagePageType["permission"] = "permission";
  3103. /**
  3104. * 数据与智能专区权限授权页
  3105. *
  3106. * 需要满足:
  3107. *
  3108. * - 企业访问者身份为超级管理员
  3109. * - 应用需要满足勾选了“数据与智能专区权限”(注:该权限目前灰度开放)
  3110. * - 应用类型为第三方应用/代开发应用(注:不支持上下游共享应用)
  3111. */ OpenAppManagePageType["datazone_permission"] = "datazone_permission";
  3112. })(exports.OpenAppManagePageType || (exports.OpenAppManagePageType = {}));
  3113. /**
  3114. * 打开应用管理页面。
  3115. *
  3116. * 应用可以使用该接口提供按钮,让企业管理员快速打开应用的管理页面。
  3117. *
  3118. * @limit
  3119. * - 本接口必须使用应用身份进行注册
  3120. * - 当前用户需要是企业超级管理员,或具有应用管理权限
  3121. *
  3122. * @compat WeCom >= 4.0.2
  3123. *
  3124. * @example
  3125. * ```
  3126. * ww.openAppManage({
  3127. * page: "permission",
  3128. * suiteId: "wwabcdefghijk",
  3129. * })
  3130. * ```
  3131. */ function openAppManage(params = {}) {
  3132. return passthrough('openAppManage', params);
  3133. }
  3134. /**
  3135. * 进入应用购买页面。
  3136. *
  3137. * 第三方应用可以使用该接口提供按钮,让用户可快速进入应用购买流程。
  3138. *
  3139. * @limit
  3140. * - 本接口必须使用应用身份进行注册
  3141. * - 当前用户应在应用的可见范围内
  3142. * - 仅第三方应用可调用
  3143. *
  3144. * @compat WeCom >= 4.1.6
  3145. *
  3146. * @example
  3147. * ```
  3148. * ww.openAppPurchase()
  3149. * ```
  3150. *
  3151. * @throws
  3152. * | errMsg | 说明 |
  3153. * | --- | --- |
  3154. * | openAppPurchase:ok | 执行成功 |
  3155. * | openAppPurchase:fail:no permission | 应用签名校验失败,或成员不在应用的可见范围内 |
  3156. * | openAppPurchase:fail | 其它错误 |
  3157. */ function openAppPurchase(params) {
  3158. return passthrough('openAppPurchase', params);
  3159. }
  3160. exports.EnvVersion = void 0;
  3161. (function(EnvVersion) {
  3162. EnvVersion["release"] = "release";
  3163. EnvVersion["trial"] = "trial";
  3164. EnvVersion["develop"] = "develop";
  3165. })(exports.EnvVersion || (exports.EnvVersion = {}));
  3166. /**
  3167. * 商户小程序跳转微信支付分小程序。
  3168. *
  3169. * @see https://pay.weixin.qq.com/wiki/doc/apiv3/payscore.php?chapter=29_3&index=3
  3170. */ function openBusinessView(params) {
  3171. return promiseToCallback(params, async ()=>{
  3172. await tryEnsureConfigReady();
  3173. const res = await invoke('openBusinessView', {
  3174. businessType: params.businessType,
  3175. queryString: params.queryString || '',
  3176. envVersion: params.envVersion
  3177. });
  3178. if (!isAndroid || !res.extraData) {
  3179. return res;
  3180. }
  3181. try {
  3182. res.extraData = JSON.parse(res.extraData);
  3183. } catch (error) {
  3184. res.extraData = {};
  3185. }
  3186. return res;
  3187. });
  3188. }
  3189. /**
  3190. * 查看设备。
  3191. *
  3192. * @limit
  3193. * 调用者必须拥有指定 deviceSn 的管理权限。
  3194. *
  3195. * @note
  3196. * 若开发者需要在 web 端引导跳转设备管理,可以构造链接跳转:`https://work.weixin.qq.com/wework_admin/frame#hardware/device?sn={{DEVICESN}}`。
  3197. *
  3198. * @compat WeCom iOS, Android >= 2.8.2
  3199. *
  3200. * @example
  3201. * ```ts
  3202. * ww.openDeviceProfile({
  3203. * deviceSn: 'QYWX001'
  3204. * })
  3205. * ```
  3206. *
  3207. * @throws
  3208. * | errMsg | 说明 |
  3209. * | --- | --- |
  3210. * | openDeviceProfile:ok | 执行成功 |
  3211. * | openDeviceProfile:fail_device_permission_denied | 管理员无设备管理权限 |
  3212. * | openDeviceProfile:fail_device_not_found | 不存在此设备 |
  3213. */ function openDeviceProfile(params) {
  3214. return passthrough('openDeviceProfile', params);
  3215. }
  3216. /**
  3217. * 打开会话。
  3218. *
  3219. * @limit
  3220. * - 内部群最多 2000 人,外部群最多 500 人
  3221. * - 若创建的会话包含微信联系人,群成员人数不能超过 40 人
  3222. * - 第三方应用与代开发应用必须使用应用身份进行注册
  3223. *
  3224. * @compat WeCom >= 2.0.0
  3225. *
  3226. * @example
  3227. * ```ts
  3228. * ww.openEnterpriseChat({
  3229. * groupName: '讨论组',
  3230. * userIds: [
  3231. * 'zhangsan',
  3232. * 'lisi'
  3233. * ],
  3234. * externalUserIds: [
  3235. * 'wmEAlECwAAHrbWYDOK5u3Bf13xlYDAAA',
  3236. * 'wmEAlECwAAHibWYDOK5u3Af13xlYDAAA'
  3237. * ]
  3238. * })
  3239. * ```
  3240. */ function openEnterpriseChat(params = {}) {
  3241. return passthrough('openEnterpriseChat', params, {
  3242. chatId: params.chatId || '',
  3243. chatname: params.groupName || '',
  3244. groupName: params.groupName || '',
  3245. useridlist: joinList(params.userIds),
  3246. userIds: joinList(params.userIds),
  3247. openIds: joinList(params.openIds),
  3248. externalUserIds: joinList(params.externalUserIds)
  3249. });
  3250. }
  3251. /**
  3252. * 打开已有群聊并可选发送一条链接消息(link消息)。支持打开企业内部群、外部群、互联群。
  3253. *
  3254. * @compat WeCom >= 3.1.8
  3255. *
  3256. * @limit
  3257. * 本接口必须使用应用身份进行注册
  3258. *
  3259. * @example
  3260. * ```ts
  3261. * ww.openExistedChatWithMsg({
  3262. * chatId: 'chatId123',
  3263. * msg: {
  3264. * msgtype: 'link',
  3265. * link: {
  3266. * title: 'title1',
  3267. * desc: 'desc1',
  3268. * url: 'link1',
  3269. * imgUrl: 'imgurl1'
  3270. * }
  3271. * }
  3272. * })
  3273. * ```
  3274. *
  3275. * @throws
  3276. * | errMsg | 说明 |
  3277. * | --- | --- |
  3278. * | openExistedChatWithMsg:ok | 执行成功 |
  3279. * | openExistedChatWithMsg:fail_unsupported_msgtype | msgtype不合法 |
  3280. * | openExistedChatWithMsg:fail_msg_link_missing_url | msg.link.url未传入 |
  3281. */ function openExistedChatWithMsg(params) {
  3282. return passthrough('openExistedChatWithMsg', params);
  3283. }
  3284. /**
  3285. * 进入应用客服会话。
  3286. *
  3287. * 第三方应用可以使用该接口提供按钮,让用户快速打开应用客服的会话。。
  3288. *
  3289. * @compat WeCom iOS, Android >= 3.1.18; WeCom PC, Mac >= 4.1.6
  3290. *
  3291. * @limit
  3292. * - 本接口必须使用应用身份进行注册
  3293. * - 仅第三方应用可调用
  3294. * - 第三方应用需要提前配置客服
  3295. * - 当前用户需要有添加外部联系人权限
  3296. *
  3297. * @example
  3298. * ```
  3299. * ww.openThirdAppServiceChat()
  3300. * ```
  3301. */ function openThirdAppServiceChat(params = {}) {
  3302. return passthrough('openThirdAppServiceChat', params);
  3303. }
  3304. exports.OpenUserProfileType = void 0;
  3305. (function(OpenUserProfileType) {
  3306. /**
  3307. * 企业成员
  3308. */ OpenUserProfileType[OpenUserProfileType["internal"] = 1] = "internal";
  3309. /**
  3310. * 外部联系人
  3311. */ OpenUserProfileType[OpenUserProfileType["external"] = 2] = "external";
  3312. })(exports.OpenUserProfileType || (exports.OpenUserProfileType = {}));
  3313. /**
  3314. * 唤起成员或外部联系人的个人信息页面。
  3315. *
  3316. * @compat WeCom >= 2.4.20
  3317. *
  3318. * @limit
  3319. * - 第三方应用调用时,需使用应用身份进行注册
  3320. *
  3321. * @example
  3322. * ```ts
  3323. * ww.openUserProfile({
  3324. * type: 1,
  3325. * userid: 'wmEAlECwAAHrbWYDetiu3Af13xlYDAAA'
  3326. * })
  3327. * ```
  3328. */ function openUserProfile(params) {
  3329. return passthrough('openUserProfile', params);
  3330. }
  3331. exports.PrintFileIdType = void 0;
  3332. (function(PrintFileIdType) {
  3333. /**
  3334. * mediaid
  3335. */ PrintFileIdType[PrintFileIdType["mediaid"] = 1] = "mediaid";
  3336. /**
  3337. * url
  3338. */ PrintFileIdType[PrintFileIdType["url"] = 2] = "url";
  3339. /**
  3340. * localId
  3341. *
  3342. * 可通过以下方式获得:
  3343. * 1. [从会话选择文件](#34301)
  3344. * 2. [拍照或从手机相册中选图接口](#14915)
  3345. */ PrintFileIdType[PrintFileIdType["localId"] = 4] = "localId";
  3346. })(exports.PrintFileIdType || (exports.PrintFileIdType = {}));
  3347. /**
  3348. * 发起文件打印。
  3349. *
  3350. * @limit
  3351. * - 本接口必须使用应用身份进行注册
  3352. * - 应用必须具有“设备信息-打印扫描设备-发起文件打印权限”授权
  3353. * - 当前触发调用人员身份需要在应用的可见范围内
  3354. * - 当前企业有安装企业微信打印设备
  3355. * - 仅第三方应用使用
  3356. *
  3357. * @compat WeCom >= 4.0.12
  3358. *
  3359. * @example
  3360. * ```ts
  3361. * ww.printFile({
  3362. * fileId: 'fileId',
  3363. * fileIdType: 1,
  3364. * fileName: 'fileName.jpg'
  3365. * })
  3366. * ```
  3367. */ function printFile(params) {
  3368. return passthrough('printFile', params);
  3369. }
  3370. exports.InTalkType = void 0;
  3371. (function(InTalkType) {
  3372. /**
  3373. * 当前不在任何通话中
  3374. */ InTalkType["None"] = "None";
  3375. /**
  3376. * 视频会议中
  3377. */ InTalkType["HWOpenTalk"] = "HWOpenTalk";
  3378. /**
  3379. * voip通话中
  3380. */ InTalkType["VoIP"] = "VoIP";
  3381. /**
  3382. * 系统通话中
  3383. */ InTalkType["SystemCall"] = "SystemCall";
  3384. })(exports.InTalkType || (exports.InTalkType = {}));
  3385. /**
  3386. * 查询当前是否在视频会议。
  3387. *
  3388. * @compat WeCom >= 2.5.0
  3389. *
  3390. * @example
  3391. * ```ts
  3392. * ww.queryCurrHWOpenTalk()
  3393. * ```
  3394. */ function queryCurrHWOpenTalk(params = {}) {
  3395. return passthrough('queryCurrHWOpenTalk', params);
  3396. }
  3397. /**
  3398. * 发起退款。
  3399. *
  3400. * @limit
  3401. * - 本接口必须使用应用身份进行注册
  3402. * - 应用必须具有对外收款权限
  3403. * - 发起的用户必须在应用可见范围并实名
  3404. * - 只允许退款由应用本身发起的收款
  3405. *
  3406. * @compat WeCom >= 4.0.12
  3407. *
  3408. * @example
  3409. * ```ts
  3410. * ww.refundExternalPayment({
  3411. * paymentId: 'xxxx',
  3412. * outTradeNo: 'yyyy',
  3413. * refundFee: 100,
  3414. * refundComment: '7天无理由退货'
  3415. * })
  3416. * ```
  3417. */ function refundExternalPayment(params) {
  3418. return passthrough('refundExternalPayment', params);
  3419. }
  3420. /**
  3421. * 保存用户选择的审批选项。
  3422. *
  3423. * 用户在网页中修改审批选项时,调用该接口保存用户的选择。
  3424. *
  3425. * @note
  3426. * - 接口仅用于审批设置外部选项场景,请勿用作其他场景
  3427. * - 网页应该做好深色模式适配
  3428. *
  3429. * @limit
  3430. * - 本接口必须使用应用身份进行注册
  3431. * - 应用必须具有审批权限
  3432. *
  3433. * @compat WeCom >= 4.0.18
  3434. *
  3435. * @example
  3436. * ```ts
  3437. * ww.saveApprovalSelectedItems({
  3438. * key: 'key',
  3439. * selectedData: [
  3440. * {
  3441. * key: 'item-1',
  3442. * value: '选项1'
  3443. * },
  3444. * {
  3445. * key: 'item-2',
  3446. * value: '选项2'
  3447. * }
  3448. * ]
  3449. * })
  3450. * ```
  3451. */ function saveApprovalSelectedItems(params) {
  3452. return passthrough('saveApprovalSelectedItems', params, {
  3453. key: params.key,
  3454. selectedData: typeof params.selectedData === 'string' ? params.selectedData : JSON.stringify(params.selectedData)
  3455. });
  3456. }
  3457. exports.ScanQRCodeType = void 0;
  3458. (function(ScanQRCodeType) {
  3459. /**
  3460. * 扫描二维码
  3461. */ ScanQRCodeType["qrCode"] = "qrCode";
  3462. /**
  3463. * 扫描条形码
  3464. */ ScanQRCodeType["barCode"] = "barCode";
  3465. })(exports.ScanQRCodeType || (exports.ScanQRCodeType = {}));
  3466. /**
  3467. * 调起企业微信扫一扫。
  3468. *
  3469. * @example
  3470. * ```ts
  3471. * ww.scanQRCode({
  3472. * needResult: true,
  3473. * scanType: ['qrCode']
  3474. * })
  3475. * ```
  3476. */ function scanQRCode(params = {}) {
  3477. return promiseToCallback(params, async ()=>{
  3478. await tryEnsureConfigReady();
  3479. const res = await invoke('scanQRCode', {
  3480. needResult: params.needResult ? 1 : 0,
  3481. scanType: params.scanType || [
  3482. 'qrCode',
  3483. 'barCode'
  3484. ]
  3485. });
  3486. if (!isIOS) {
  3487. return res;
  3488. }
  3489. const resultStr = res.resultStr;
  3490. if (!resultStr) {
  3491. return res;
  3492. }
  3493. let data;
  3494. try {
  3495. data = JSON.parse(resultStr);
  3496. } catch (error) {
  3497. // noop
  3498. }
  3499. res.resultStr = data?.scan_code?.scan_result;
  3500. return res;
  3501. });
  3502. }
  3503. exports.InputCorpGroupContactMode = void 0;
  3504. (function(InputCorpGroupContactMode) {
  3505. /**
  3506. * 单选
  3507. */ InputCorpGroupContactMode["single"] = "single";
  3508. /**
  3509. * 多选
  3510. */ InputCorpGroupContactMode["multi"] = "multi";
  3511. })(exports.InputCorpGroupContactMode || (exports.InputCorpGroupContactMode = {}));
  3512. exports.InputCorpGroupContactType = void 0;
  3513. (function(InputCorpGroupContactType) {
  3514. /**
  3515. * 选择部门
  3516. */ InputCorpGroupContactType["department"] = "department";
  3517. /**
  3518. * 选择成员
  3519. */ InputCorpGroupContactType["user"] = "user";
  3520. })(exports.InputCorpGroupContactType || (exports.InputCorpGroupContactType = {}));
  3521. /**
  3522. * 企业互联/上下游选人
  3523. *
  3524. * @limit
  3525. * - 本接口必须使用应用身份进行注册
  3526. * - 该接口仅可选择应用可见范围内的成员和部门
  3527. *
  3528. * @compat WeCom iOS, Android, PC >= 3.1.6
  3529. *
  3530. * @note
  3531. * 自建应用调用该接口时userid返回的是企业内部的userid,对于服务商该字段返回的是open_userid,同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节
  3532. *
  3533. * @example
  3534. * ```ts
  3535. * ww.selectCorpGroupContact({
  3536. * fromDepartmentId: -1,
  3537. * mode: 'single',
  3538. * type: ['department', 'user'],
  3539. * selectedDepartmentIds: ['2','3'],
  3540. * selectedUserIds: ['lisi','lisi2'],
  3541. * selectedOpenUserIds: ['wabc3','wbcde'],
  3542. * selectedChainDepartmentIds: [
  3543. * {
  3544. * corpId: 'ww3333',
  3545. * departmentId: '2'
  3546. * },
  3547. * {
  3548. * corpId: 'ww4444',
  3549. * departmentId: '3'
  3550. * }
  3551. * ],
  3552. * selectedChainUserIds: [
  3553. * {
  3554. * corpId: 'ww3333',
  3555. * userId: 'userid123',
  3556. * openUserId: 'wx1111'
  3557. * },
  3558. * {
  3559. * corpId: 'ww4444',
  3560. * userId: 'userid123',
  3561. * openUserId: 'wx1111'
  3562. * }
  3563. * ],
  3564. * selectedCorpGroupDepartmentIds: [
  3565. * {
  3566. * corpId: 'ww3333',
  3567. * departmentId: '2'
  3568. * },
  3569. * {
  3570. * corpId: 'ww4444',
  3571. * departmentId: '3'
  3572. * }
  3573. * ],
  3574. * selectedCorpGroupUserIds: [
  3575. * {
  3576. * corpId: 'ww3333',
  3577. * userId: 'userid123',
  3578. * openUserId: 'wx1111'
  3579. * },
  3580. * {
  3581. * corpId: 'ww4444',
  3582. * userId: 'userid123',
  3583. * openUserId: 'wx1111'
  3584. * }
  3585. * ]
  3586. * })
  3587. * ```
  3588. * @throws
  3589. * | errMsg | 说明 |
  3590. * | --- | --- |
  3591. * | selectCorpGroupContact:ok | 执行成功 |
  3592. * | selectCorpGroupContact:fail no permission | 应用身份鉴权失败 |
  3593. *
  3594. */ function selectCorpGroupContact(params) {
  3595. return promiseToCallback(params, async ()=>{
  3596. await tryEnsureConfigReady();
  3597. const res = await invoke('selectCorpGroupContact', params);
  3598. if (!isString(res.result)) {
  3599. return res;
  3600. }
  3601. try {
  3602. res.result = JSON.parse(res.result);
  3603. } catch (error) {
  3604. // noop
  3605. }
  3606. return res;
  3607. });
  3608. }
  3609. exports.SelectEnterpriseContactMode = void 0;
  3610. (function(SelectEnterpriseContactMode) {
  3611. /**
  3612. * 单选
  3613. */ SelectEnterpriseContactMode["single"] = "single";
  3614. /**
  3615. * 多选
  3616. */ SelectEnterpriseContactMode["multi"] = "multi";
  3617. })(exports.SelectEnterpriseContactMode || (exports.SelectEnterpriseContactMode = {}));
  3618. exports.SelectEnterpriseContactType = void 0;
  3619. (function(SelectEnterpriseContactType) {
  3620. /**
  3621. * 选择部门
  3622. */ SelectEnterpriseContactType["department"] = "department";
  3623. /**
  3624. * 选择成员
  3625. */ SelectEnterpriseContactType["user"] = "user";
  3626. })(exports.SelectEnterpriseContactType || (exports.SelectEnterpriseContactType = {}));
  3627. /**
  3628. * 选择通讯录成员。
  3629. *
  3630. * @compat WeCom >= 1.3.11; WeChat iOS, Android >= 6.5.10
  3631. *
  3632. * @example
  3633. * ```ts
  3634. * ww.selectEnterpriseContact({
  3635. * fromDepartmentId: -1,
  3636. * mode: 'multi',
  3637. * type: ['department', 'user'],
  3638. * selectedDepartmentIds: ['2', '3'],
  3639. * selectedUserIds: ['lisi', 'lisi2']
  3640. * })
  3641. * ```
  3642. */ function selectEnterpriseContact(params) {
  3643. return promiseToCallback(params, async ()=>{
  3644. await tryEnsureConfigReady();
  3645. const res = await invoke('selectEnterpriseContact', params);
  3646. if (!isString(res.result)) {
  3647. return res;
  3648. }
  3649. try {
  3650. res.result = JSON.parse(res.result);
  3651. } catch (error) {
  3652. // noop
  3653. }
  3654. return res;
  3655. });
  3656. }
  3657. exports.SelectExternalContactType = void 0;
  3658. (function(SelectExternalContactType) {
  3659. /**
  3660. * 展示全部外部联系人列表
  3661. */ SelectExternalContactType[SelectExternalContactType["all"] = 0] = "all";
  3662. /**
  3663. * 仅展示未曾选择过的外部联系人
  3664. */ SelectExternalContactType[SelectExternalContactType["unselected"] = 1] = "unselected";
  3665. })(exports.SelectExternalContactType || (exports.SelectExternalContactType = {}));
  3666. /**
  3667. * 唤起该成员的外部联系人列表,并返回员工选择的外部联系人的 userId。
  3668. *
  3669. * @limit
  3670. * - 本接口必须使用应用身份进行注册
  3671. * - 应用须配置[客户联系功能权限](#13473/配置可使用客户联系接口的应用)
  3672. * - 当前成员必须配置[客户联系功能](#13473/开始开发)
  3673. *
  3674. * @compat WeCom >= 2.4.20
  3675. *
  3676. * @example
  3677. * ```ts
  3678. * ww.selectExternalContact({
  3679. * filterType: 0
  3680. * })
  3681. * ```
  3682. */ function selectExternalContact(params = {}) {
  3683. return passthrough('selectExternalContact', params);
  3684. }
  3685. exports.SelectPrivilegedContactMode = void 0;
  3686. (function(SelectPrivilegedContactMode) {
  3687. /**
  3688. * 单选
  3689. */ SelectPrivilegedContactMode["single"] = "single";
  3690. /**
  3691. * 多选
  3692. */ SelectPrivilegedContactMode["multi"] = "multi";
  3693. })(exports.SelectPrivilegedContactMode || (exports.SelectPrivilegedContactMode = {}));
  3694. /**
  3695. * 返回 ticket 的选人接口。
  3696. *
  3697. * 用于第三方应用唤起选择企业通讯录成员,用户选择的范围区分成两部分回传给第三方应用:
  3698. *
  3699. * 1. 过滤应用可见范围后的 openUserId 列表
  3700. * 2. 完整列表的 ticket,ticket 后续可用于[创建群聊](#30292) 或者[发送模板消息](#94515)
  3701. *
  3702. * @limit
  3703. * - 本接口必须使用应用身份进行注册
  3704. * - 仅第三方应用(非通讯录应用)可调用
  3705. *
  3706. * @compat WeCom >= 3.1.8
  3707. *
  3708. * @example
  3709. * ```ts
  3710. * ww.selectPrivilegedContact({
  3711. * fromDepartmentId: -1,
  3712. * mode: 'multi',
  3713. * selectedContextContact: 1
  3714. * selectedOpenUserIds: ['xxx', 'yyy'],
  3715. * selectedTickets: ['ticket1', 'ticket2']
  3716. * })
  3717. * ```
  3718. */ function selectPrivilegedContact(params) {
  3719. return passthrough('selectPrivilegedContact', params);
  3720. }
  3721. /**
  3722. * 从聊天工具栏或附件栏打开的页面中向当前会话发送消息
  3723. *
  3724. * @note
  3725. * 消息格式支持文本(“text”),图片(“image”),视频(“video”),文件(“file”),H5(“news”),小程序(“miniprogram”),菜单消息(“msgmenu”)和视频号商品(“channels_shop_product”)
  3726. *
  3727. * @limit
  3728. * - 本接口必须使用应用身份进行注册
  3729. * - 仅从特定入口进入页面才可调用,可通过 getContext 接口进行判断
  3730. * - 不同的入口对应用及用户有相应的限制
  3731. * | getContext 接口返回的 entry 值 | 自建应用 | 第三方应用 | 用户 | 支持的最低版本 |
  3732. * | --- | --- | --- | --- | --- |
  3733. * | single_chat_tools | 需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用) | 需有“企业客户权限->客户基础信息”权限 | 配置了|[配置了客户联系功能](#13473/配置可使用客户联系功能的成员) | 企业微信 2.8.10 |
  3734. * | group_chat_tools | 需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用) | 需有“企业客户权限->客户基础信息”权限 | 配置了|[配置了客户联系功能](#13473/配置可使用客户联系功能的成员) | 企业微信 2.8.10 |
  3735. * | group_chat_tools | 所有 | 需有「家校沟通」使用权限 | 所有 | 企业微信 3.0.36 |
  3736. * | group_chat_tools | 所有 | 需有「家校沟通」使用权限 | 所有 | 企业微信 4.0.8 |
  3737. * | chat_attachment | 所有 | 所有 | 所有 | 企业微信 3.1.6(mac 端暂不支持) |
  3738. * | single_kf_tools | 所有 | 需有“微信客服权限->获取基础信息”权限 | 所有 | 企业微信 3.1.10 |
  3739. * - 消息中的 mediaId 可通过[素材管理](#10112)接口获得,暂不支持公众平台的 mediaId
  3740. *
  3741. * @compat WeCom >= 2.8.10
  3742. *
  3743. * @example
  3744. * ```ts
  3745. * ww.sendChatMessage({
  3746. * msgtype: 'text',
  3747. * text: {
  3748. * content: '你好'
  3749. * }
  3750. * })
  3751. * ```
  3752. *
  3753. * @throws
  3754. * | errMsg | 说明 |
  3755. * | --- | --- |
  3756. * | sendChatMessage:ok | 执行成功 |
  3757. * | claimClassAdmin:fail without context of external contact | 当前页面打开的场景不支持调用 |
  3758. * | claimClassAdmin:fail no permission | 应用签名错误,或不满足权限要求 |
  3759. * | claimClassAdmin:fail invalid imgUrl | 小程序消息封面图不合法 |
  3760. */ function sendChatMessage(params) {
  3761. return passthrough('sendChatMessage', params);
  3762. }
  3763. /**
  3764. * 设置私密消息。
  3765. *
  3766. * @compat WeCom >= 3.1.8
  3767. *
  3768. * @limit
  3769. * 本接口必须使用应用身份进行注册
  3770. *
  3771. * @example
  3772. * ```ts
  3773. * ww.setShareAttr({
  3774. * withShareTicket: true,
  3775. * state: 'STATE'
  3776. * })
  3777. * ```
  3778. */ function setShareAttr(params = {}) {
  3779. return passthrough('setShareAttr', params);
  3780. }
  3781. /**
  3782. * 具有客户联系权限的企业成员,可通过该接口将文本内容和附件传递到客户群群发、发送到客户群。
  3783. *
  3784. * @limit
  3785. * - 本接口必须使用应用身份进行注册
  3786. * - 应用需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用)
  3787. * - 当前成员必须配置了[客户联系功能](#13473/配置可使用客户联系功能的成员)
  3788. *
  3789. * @note
  3790. * - 为防止滥用,同一个成员每日向一个客户最多可群发一条消息,每次群发最多可选 2000 个最近活跃的客户群
  3791. *
  3792. * @compat WeCom >= 2.8.7
  3793. *
  3794. * @example
  3795. * ```ts
  3796. * // WeCom >= 3.1.6
  3797. * ww.shareToExternalChat({
  3798. * chatIds: ["wr2GCAAAXAAAaWJHDDGasdadAAA","wr2GCAAAXBBBaWJHDDGasdadBBB"],
  3799. * text: {
  3800. * content: '企业微信'
  3801. * },
  3802. * attachments: [
  3803. * {
  3804. * msgtype: 'image',
  3805. * image: {
  3806. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png'
  3807. * }
  3808. * }
  3809. * ]
  3810. * })
  3811. * // 或者
  3812. * ww.shareToExternalChat({
  3813. * title: '', // 消息的标题
  3814. * desc: '', // 消息的描述
  3815. * link: '', // 消息链接
  3816. * imgUrl: '' // 消息封面
  3817. * })
  3818. * ```
  3819. */ function shareToExternalChat(params) {
  3820. return passthrough('shareToExternalChat', params);
  3821. }
  3822. /**
  3823. * 具有客户联系权限的企业成员,可通过该接口将文本内容和附件传递到群发助手、发送给客户。
  3824. *
  3825. * @limit
  3826. * - 本接口必须使用应用身份进行注册
  3827. * - 应用需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用)
  3828. * - 当前成员必须配置了[客户联系功能](#13473/配置可使用客户联系功能的成员)
  3829. *
  3830. * @note
  3831. * - 为防止滥用,同一个成员每日向一个客户最多可群发一条消息,每次群发最多可选 20000 个客户
  3832. *
  3833. *
  3834. * @compat WeCom >= 2.8.7
  3835. *
  3836. * @example
  3837. * ```ts
  3838. * // WeCom >= 3.1.6
  3839. * ww.shareToExternalContact({
  3840. * externalUserIds: ["wr2GCAAAXAAAaWJHDDGasdadAAA","wr2GCAAAXBBBaWJHDDGasdadBBB"],
  3841. * text: {
  3842. * content: '企业微信'
  3843. * },
  3844. * attachments: [
  3845. * {
  3846. * msgtype: 'image',
  3847. * image: {
  3848. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png'
  3849. * }
  3850. * }
  3851. * ]
  3852. * })
  3853. *
  3854. * // 或者
  3855. * ww.shareToExternalContact({
  3856. * title: '', // 消息的标题
  3857. * desc: '', // 消息的描述
  3858. * link: '', // 消息链接
  3859. * imgUrl: '' // 消息封面
  3860. * })
  3861. * ```
  3862. */ function shareToExternalContact(params) {
  3863. return passthrough('shareToExternalContact', params);
  3864. }
  3865. /**
  3866. * 发表内容到客户朋友圈。
  3867. *
  3868. * @limit
  3869. * - 本接口必须使用应用身份进行注册
  3870. * - 应用需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用)
  3871. * - 当前成员必须配置了客户联系功能
  3872. * - 当前成员必须在客户朋友圈使用范围
  3873. * - 当前成员必须具备外部沟通管理成员使用权限
  3874. *
  3875. * @compat WeCom iOS, Android >= 3.1.12
  3876. *
  3877. * @example
  3878. * ```ts
  3879. * ww.shareToExternalMoments({
  3880. * text: {
  3881. * content: '企业微信'
  3882. * },
  3883. * attachments: [
  3884. * {
  3885. * msgtype: 'image',
  3886. * image: {
  3887. * imgUrl: 'https://res.mail.qq.com/node/ww/wwmng/style/images/index_share_logo$13c64306.png'
  3888. * }
  3889. * }
  3890. * ]
  3891. * })
  3892. * ```
  3893. */ function shareToExternalMoments(params) {
  3894. return passthrough('shareToExternalMoments', params);
  3895. }
  3896. /**
  3897. * 发起无线投屏。
  3898. *
  3899. * @compat WeCom
  3900. *
  3901. * @limit
  3902. * 仅支持第三方服务商接入。
  3903. * 需要配合硬件设备使用,硬件接入流程参考 [无线投屏](#14789)。
  3904. *
  3905. * @example
  3906. * ```ts
  3907. * ww.startWecast()
  3908. * ```
  3909. */ function startWecast(params = {}) {
  3910. return passthrough('startWecast', params);
  3911. }
  3912. exports.OAType = void 0;
  3913. (function(OAType) {
  3914. /**
  3915. * 发起审批
  3916. */ OAType["create_approval"] = "10001";
  3917. /**
  3918. * 查看审批详情
  3919. */ OAType["view_approval"] = "10002";
  3920. })(exports.OAType || (exports.OAType = {}));
  3921. exports.OaExtDataType = void 0;
  3922. (function(OaExtDataType) {
  3923. /**
  3924. * 链接
  3925. */ OaExtDataType["link"] = "link";
  3926. /**
  3927. * 文本
  3928. */ OaExtDataType["text"] = "text";
  3929. })(exports.OaExtDataType || (exports.OaExtDataType = {}));
  3930. /**
  3931. * 在应用页面中发起审批流程。之后审批流程的每次状态变化都会通知开发者,开发者可按需进行拓展开发。具体参见[审批流程引擎](#14584)。
  3932. *
  3933. * @limit
  3934. * - 本接口必须使用应用身份进行注册
  3935. * - 应用必须具有审批权限
  3936. *
  3937. * @compat WeCom >= 2.5.0
  3938. *
  3939. * @example
  3940. * ```ts
  3941. * ww.thirdPartyOpenPage({
  3942. * oaType: '10001',
  3943. * templateId: '46af67a118a6ebf000002',
  3944. * thirdNo: 'thirdNo',
  3945. * extData: {
  3946. * fieldList: [
  3947. * {
  3948. * type: 'text',
  3949. * title: '采购类型',
  3950. * value: '市场活动'
  3951. * },
  3952. * {
  3953. * type: 'link',
  3954. * title: '订单链接',
  3955. * value: 'https://work.weixin.qq.com'
  3956. * }
  3957. * ]
  3958. * }
  3959. * })
  3960. * ```
  3961. * @throws
  3962. * | errMsg | 说明 |
  3963. * | --- | --- |
  3964. * | 已存在相同的审批编号 | oaType为10001时,传入的thirdNo已经被其他审批单占用。 |
  3965. * | 审批申请不存在 | oaType为10002时,在历史记录中,传入的thirdNo对应的审批单不存在。 |
  3966. * | 审批模板ID不正确 | 调用接口时传入了错误的templateId |
  3967. * | 应用ID不正确 | 使用了错误的 agentId |
  3968. */ function thirdPartyOpenPage(params) {
  3969. return passthrough('thirdPartyOpenPage', params);
  3970. }
  3971. /**
  3972. * 变更企业互联/上下游群成员
  3973. *
  3974. * @limit
  3975. * - 本接口必须使用应用身份进行注册
  3976. * - 当前成员必须在应用的可见范围
  3977. * - 仅支持往群里添加企业内部成员/企业互联成员
  3978. * - 仅限企业互联/上下游企业可调用
  3979. * - 当前成员为下游企业成员时,需要打开上下游空间中的“允许外部单位之间互相查看”配置才可以往群里添加其他下游企业成员
  3980. *
  3981. * @compat WeCom >= 3.1.8
  3982. *
  3983. * @example
  3984. * ```ts
  3985. * ww.updateCorpGroupChat({
  3986. * chatId: 'CHATID',
  3987. * userIdsToAdd: ['lisi', 'lisi2'],
  3988. * openUserIdsToAdd: ['wabc3', 'wbcde'],
  3989. * corpGroupUserIdsToAdd: [
  3990. * {
  3991. * corpId: 'ww3333',
  3992. * userId: 'userid123',
  3993. * openUserId: 'wx1111'
  3994. * },
  3995. * {
  3996. * corpId: 'ww4444',
  3997. * userId: 'userid123',
  3998. * openUserId: 'wx1111'
  3999. * }
  4000. * ]
  4001. * })
  4002. * ```
  4003. *
  4004. * @throws
  4005. * | errMsg | 说明 |
  4006. * | --- | --- |
  4007. * | updateCorpGroupChat:ok | 执行成功 |
  4008. * | updateCorpGroupChat:fail no permission | 应用签名校验失败 |
  4009. * | updateCorpGroupChat:fail exceed user id list size | 超过人数上限 |
  4010. * | updateCorpGroupChat:fail invalid parameter | 参数不合法 |
  4011. * | updateCorpGroupChat:fail unsupported chat | 不支持群类型 |
  4012. */ function updateCorpGroupChat(params) {
  4013. return passthrough('updateCorpGroupChat', params);
  4014. }
  4015. /**
  4016. * 变更群成员。
  4017. *
  4018. * @limit
  4019. * - 本接口必须使用应用身份进行注册
  4020. * - 目前仅支持添加企业内部成员
  4021. * - 仅支持客户群调用
  4022. *
  4023. * @compat WeCom iOS, Android, PC >= 3.0.36
  4024. *
  4025. * @example
  4026. * ```ts
  4027. * ww.updateEnterpriseChat({
  4028. * chatId: 'CHATID',
  4029. * userIdsToAdd: [
  4030. * 'zhangsan',
  4031. * 'lisi'
  4032. * ]
  4033. * })
  4034. * ```
  4035. */ function updateEnterpriseChat(params) {
  4036. return passthrough('updateEnterpriseChat', params, {
  4037. chatId: params.chatId,
  4038. userIdsToAdd: joinList(params.userIdsToAdd)
  4039. });
  4040. }
  4041. /**
  4042. * 设置朋友圈封面与签名。
  4043. *
  4044. * @compat WeCom iOS, Android >= 3.1.12
  4045. *
  4046. * @limit
  4047. * - 本接口必须使用应用身份进行注册
  4048. * - 应用需有[客户联系功能权限](#13473/配置可使用客户联系接口的应用)
  4049. * - 当前成员必须配置了客户联系功能
  4050. * - 当前成员必须在客户朋友圈使用范围
  4051. * - 当前成员必须具备外部沟通管理成员使用权限
  4052. *
  4053. * @note
  4054. * 同时设置了签名跟封面url,客户端更新顺序为先更新签名,再更新封面图url(封面图若不符合要求会让用户重新调整)。
  4055. *
  4056. * @example
  4057. * ```ts
  4058. * ww.updateMomentsSetting({
  4059. * signature: '个性签名',
  4060. * imgUrl: 'https://work.weixin.qq.com/'
  4061. * })
  4062. * ```
  4063. */ function updateMomentsSetting(params) {
  4064. return passthrough('updateMomentsSetting', params);
  4065. }
  4066. /**
  4067. * 保持屏幕常亮。
  4068. *
  4069. * 在企业微信内打开 H5 页面时,调用该接口让屏幕保持常亮。
  4070. *
  4071. * @note
  4072. * 仅在当前页面生效,离开页面后设置失效。
  4073. *
  4074. * @limit
  4075. * - 本接口必须使用应用身份进行注册
  4076. * - 成员必须在应用可见范围内
  4077. *
  4078. * @compat @compat WeCom iOS, Android >= 4.0.20
  4079. *
  4080. * @example
  4081. * ```ts
  4082. * ww.setKeepScreenOn({
  4083. * keepScreenOn: true,
  4084. * })
  4085. * ```
  4086. */ function setKeepScreenOn(params) {
  4087. return passthrough('setKeepScreenOn', params);
  4088. }
  4089. /**
  4090. * **注意:页面上需要提前引入 `jwxwork-1.0.0.js`:**
  4091. *
  4092. * ```html
  4093. * <script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js" referrerpolicy="origin"></script>
  4094. * ```
  4095. *
  4096. * 初始化[通讯录展示组件](#91958)。
  4097. *
  4098. * 在该接口返回成功后,可以直接调用通讯录展示组件的相关方法。
  4099. *
  4100. * @example
  4101. * ```ts
  4102. * ww.initOpenData()
  4103. * ```
  4104. */ function initOpenData(params = {}) {
  4105. return promiseToCallback(params, async ()=>{
  4106. if (!isWeCom) {
  4107. return invokeOpenDataAgentConfig();
  4108. }
  4109. const { result } = await ensureAgentConfigReady();
  4110. if (!isWindows && !win?.WeixinSandBox) {
  4111. throw new SDKError('Missing WeixinSandBox');
  4112. }
  4113. if (!win?.WWOpenData) {
  4114. await invoke('wwapp.initWwOpenData');
  4115. }
  4116. if (!win?.WWOpenData) {
  4117. throw new SDKError('Init WWOpenData failed');
  4118. }
  4119. if (win.WWOpenData.initJSSDK) {
  4120. win.WWOpenData.initJSSDK({
  4121. invoke,
  4122. ensureAgentConfigReady
  4123. });
  4124. }
  4125. return result;
  4126. });
  4127. }
  4128. async function invokeOpenDataAgentConfig() {
  4129. if (!win?.WWOpenData?.agentConfig) {
  4130. throw new SDKError('Missing WWOpenData.agentConfig');
  4131. }
  4132. const params = await resolveAgentConfigParams(getSignURL());
  4133. const promise = new Promise((success, fail)=>{
  4134. win.WWOpenData.agentConfig({
  4135. ...params,
  4136. success,
  4137. fail
  4138. });
  4139. });
  4140. promise.then(handleAgentConfigSuccess, handleAgentConfigFail);
  4141. return promise;
  4142. }
  4143. function createTransparentIFrame(el) {
  4144. const iframeEl = document.createElement('iframe');
  4145. const { style } = iframeEl;
  4146. style.display = 'block';
  4147. style.border = 'none';
  4148. style.background = 'transparent';
  4149. iframeEl.referrerPolicy = 'origin';
  4150. iframeEl.setAttribute('frameborder', '0');
  4151. iframeEl.setAttribute('allowtransparency', 'true');
  4152. const containerEl = resolveEl(el);
  4153. if (containerEl) {
  4154. containerEl.appendChild(iframeEl);
  4155. }
  4156. return iframeEl;
  4157. }
  4158. function resolveEl(el) {
  4159. if (typeof el === 'string') {
  4160. return document.querySelector(el);
  4161. }
  4162. return el;
  4163. }
  4164. const clientId = random();
  4165. let uid = 0;
  4166. function genUid() {
  4167. return `${clientId}-${uid++}`;
  4168. }
  4169. function random() {
  4170. return Math.random().toString(36).slice(2);
  4171. }
  4172. function normalizeError(error) {
  4173. if (!error || typeof error !== 'object') {
  4174. return error;
  4175. }
  4176. return {
  4177. ...error,
  4178. message: error.message,
  4179. stack: error.stack
  4180. };
  4181. }
  4182. function tryParseJSON(data) {
  4183. try {
  4184. if (typeof data === 'string') {
  4185. return JSON.parse(data);
  4186. }
  4187. return data;
  4188. } catch (error) {
  4189. // noop
  4190. }
  4191. }
  4192. function useRemoteInvoke(postMessage, callback) {
  4193. const messageMap = new Map();
  4194. function invoke(args, opts) {
  4195. if (opts?.dropResult) {
  4196. postMessage({
  4197. type: 'ww-iframe-handle:call',
  4198. args
  4199. }, opts);
  4200. return Promise.resolve(undefined);
  4201. }
  4202. return new Promise((resolve, reject)=>{
  4203. const uid = genUid();
  4204. messageMap.set(uid, {
  4205. resolve,
  4206. reject
  4207. });
  4208. postMessage({
  4209. type: 'ww-iframe-handle:call',
  4210. uid,
  4211. args
  4212. }, opts);
  4213. });
  4214. }
  4215. async function handleCallMessage(msg, event) {
  4216. if (!msg.uid) {
  4217. return callback(msg.args, event);
  4218. }
  4219. try {
  4220. postMessage({
  4221. type: 'ww-iframe-handle:response',
  4222. uid: msg.uid,
  4223. kind: 'resolve',
  4224. args: await callback(msg.args, event)
  4225. });
  4226. } catch (error) {
  4227. postMessage({
  4228. type: 'ww-iframe-handle:response',
  4229. uid: msg.uid,
  4230. kind: 'reject',
  4231. args: normalizeError(error)
  4232. });
  4233. throw error;
  4234. }
  4235. }
  4236. function handleResponseMessage(msg) {
  4237. const handle = messageMap.get(msg.uid);
  4238. if (!handle) {
  4239. return;
  4240. }
  4241. handle[msg.kind](msg.args);
  4242. messageMap.delete(msg.uid);
  4243. }
  4244. return {
  4245. invoke,
  4246. handleCallMessage,
  4247. handleResponseMessage
  4248. };
  4249. }
  4250. function useIframeClient(iframeEl, origin, callback) {
  4251. const messageQueue = [];
  4252. let iframeReady = false;
  4253. let useChannel = false;
  4254. window.addEventListener('message', handleWindowMessage);
  4255. function handleWindowMessage(event) {
  4256. if (event.origin !== origin || iframeEl.contentWindow !== event.source) {
  4257. return;
  4258. }
  4259. const msg = tryParseJSON(event.data);
  4260. if (typeof msg?.type !== 'string') {
  4261. return;
  4262. }
  4263. if (msg.type.startsWith('ww-iframe-handle:')) {
  4264. handleMessage(msg, event);
  4265. }
  4266. }
  4267. const channel = new MessageChannel();
  4268. channel.port1.onmessage = (event)=>{
  4269. const msg = tryParseJSON(event.data);
  4270. handleMessage(msg, event);
  4271. };
  4272. const { invoke, handleCallMessage, handleResponseMessage } = useRemoteInvoke(enqueueMsg, callback);
  4273. function handleMessage(msg, event) {
  4274. switch(msg.type){
  4275. case 'ww-iframe-handle:ready':
  4276. return handleReadyMessage(msg);
  4277. case 'ww-iframe-handle:call':
  4278. return handleCallMessage(msg, event);
  4279. case 'ww-iframe-handle:response':
  4280. handleResponseMessage(msg);
  4281. return;
  4282. }
  4283. }
  4284. function handleReadyMessage(msg) {
  4285. if (iframeReady) {
  4286. return;
  4287. }
  4288. iframeReady = true;
  4289. if (msg.supportChannel) {
  4290. switchToChannel();
  4291. }
  4292. for (const info of messageQueue){
  4293. postMessage(info.msg, info.opts);
  4294. }
  4295. }
  4296. iframeEl.addEventListener('load', ()=>{
  4297. if (!iframeReady) {
  4298. postMessage({
  4299. type: 'ww-iframe-handle:init'
  4300. });
  4301. }
  4302. });
  4303. function switchToChannel() {
  4304. postMessage({
  4305. type: 'ww-iframe-handle:set-port',
  4306. port: channel.port2
  4307. }, {
  4308. transfer: [
  4309. channel.port2
  4310. ],
  4311. serialize: false
  4312. });
  4313. useChannel = true;
  4314. }
  4315. function enqueueMsg(msg, opts) {
  4316. if (!iframeReady) {
  4317. messageQueue.push({
  4318. msg,
  4319. opts
  4320. });
  4321. } else {
  4322. postMessage(msg, opts);
  4323. }
  4324. }
  4325. function postMessage(msg, opts) {
  4326. const data = opts?.serialize === false ? msg : JSON.stringify(msg);
  4327. if (useChannel) {
  4328. channel.port1.postMessage(data, opts?.transfer);
  4329. } else {
  4330. iframeEl.contentWindow?.postMessage(data, origin, opts?.transfer);
  4331. }
  4332. }
  4333. function dispose() {
  4334. window.removeEventListener('message', handleWindowMessage);
  4335. channel.port1.onmessage = null;
  4336. }
  4337. return {
  4338. el: iframeEl,
  4339. invoke,
  4340. dispose
  4341. };
  4342. }
  4343. async function resolveSuiteConfigParams(url) {
  4344. const registerOptions = getRegisterOptions();
  4345. if (!registerOptions?.getSuiteConfigSignature) {
  4346. throw new SDKError('Missing getSuiteConfigSignature');
  4347. }
  4348. const data = await registerOptions.getSuiteConfigSignature(url);
  4349. return {
  4350. suiteid: registerOptions.suiteId,
  4351. timestamp: `${data.timestamp}`,
  4352. nonceStr: data.nonceStr,
  4353. signature: data.signature,
  4354. jsApiList: mapJsApiListToClient(registerOptions.jsApiList || [
  4355. 'agentConfig'
  4356. ])
  4357. };
  4358. }
  4359. function has$1(obj, key) {
  4360. return Object.prototype.hasOwnProperty.call(obj, key);
  4361. }
  4362. function handleCallMsg(msg, options, thisArg) {
  4363. safeRun(options[msg.name], msg.payload || msg.data, thisArg);
  4364. }
  4365. function createMsgDispatcher() {
  4366. const handlers = new Map();
  4367. function subscribe(type, handler) {
  4368. handlers.set(type, handler);
  4369. }
  4370. function handleMessage(msg) {
  4371. return handlers.get(msg.type)?.(msg);
  4372. }
  4373. return {
  4374. subscribe,
  4375. handleMessage
  4376. };
  4377. }
  4378. let disposeModalFrame;
  4379. function showModalFrame(url, callback) {
  4380. disposeModalFrame?.();
  4381. const iframeEl = createTransparentIFrame(document.body);
  4382. const { style } = iframeEl;
  4383. style.position = 'fixed';
  4384. style.left = '0';
  4385. style.top = '0';
  4386. style.zIndex = '1000';
  4387. style.width = '100vw';
  4388. style.height = '100vh';
  4389. iframeEl.classList.add('wecom-jssdk-modal');
  4390. iframeEl.setAttribute('src', url);
  4391. const { origin } = new URL(url);
  4392. const client = useIframeClient(iframeEl, origin, (msg)=>{
  4393. if (msg.type === 'close') {
  4394. handleCloseMsg();
  4395. }
  4396. return callback?.(msg);
  4397. });
  4398. function handleCloseMsg() {
  4399. client.dispose();
  4400. iframeEl.parentNode?.removeChild(iframeEl);
  4401. }
  4402. disposeModalFrame = handleCloseMsg;
  4403. return client;
  4404. }
  4405. const FRAME_ORIGIN$1 = 'https://login.work.weixin.qq.com';
  4406. /**
  4407. * 创建 JSAPI 触发面板。
  4408. *
  4409. * 在非企业微信内置浏览器环境下,开发者可以创建 JSAPI 触发面板。当用户点击面板时,内置的 iframe 将调起用户本地的企业微信客户端并调用指定的 JSAPI。
  4410. *
  4411. * @param name 要调用的 JSAPI 名称
  4412. *
  4413. * @limit
  4414. * - 应用必须经过 SSO 登录获取 web_token
  4415. * - 用户必须登录了企业微信桌面端且当前用户身份和页面身份一致
  4416. */ function createJSAPIPanel(name, options) {
  4417. const iframeEl = createTransparentIFrame(options.el);
  4418. const { style } = iframeEl;
  4419. style.width = '100%';
  4420. style.height = '100%';
  4421. const jsapiParamsMap = new Map();
  4422. const { subscribe, handleMessage } = createMsgDispatcher();
  4423. const { dispose } = useIframeClient(iframeEl, FRAME_ORIGIN$1, handleMessage);
  4424. subscribe('call', (msg)=>{
  4425. handleCallMsg(msg, options);
  4426. });
  4427. subscribe('getStaticOptions', ()=>{
  4428. return {
  4429. name,
  4430. options: {
  4431. ...options,
  4432. el: undefined,
  4433. params: undefined
  4434. }
  4435. };
  4436. });
  4437. subscribe('jsapiCallback', (msg)=>{
  4438. if (!jsapiParamsMap.has(msg.seq)) {
  4439. return;
  4440. }
  4441. const jsapiParams = jsapiParamsMap.get(msg.seq);
  4442. jsapiParamsMap.delete(msg.seq);
  4443. if (msg.kind === 'success') {
  4444. safeRun(jsapiParams?.success, msg.payload);
  4445. } else {
  4446. safeRun(jsapiParams?.fail, msg.payload);
  4447. }
  4448. safeRun(jsapiParams?.complete, msg.payload);
  4449. });
  4450. subscribe('getJSAPIParams', async (msg)=>{
  4451. const jsapiParams = isFunction(options.params) ? await options.params() : options.params;
  4452. const signUrl = getSignURL();
  4453. jsapiParamsMap.set(msg.seq, jsapiParams);
  4454. return {
  4455. webToken: options.webToken,
  4456. url: signUrl,
  4457. configParams: msg.payload?.skipSignature ? undefined : await resolveSignatureData(signUrl, msg.payload?.preferSignatureTypeList || [
  4458. 'agentConfig'
  4459. ]),
  4460. jsapi: name,
  4461. jsapiParams
  4462. };
  4463. });
  4464. subscribe('openModalFrame', (msg)=>{
  4465. showModalFrame(msg.payload.url);
  4466. });
  4467. iframeEl.style.opacity = '0';
  4468. iframeEl.src = 'https://login.work.weixin.qq.com/wwopen/ww-jsapi-transparent-frame';
  4469. return {
  4470. /**
  4471. * JSAPI 触发面板的 iframe 元素
  4472. */ el: iframeEl,
  4473. /**
  4474. * 卸载 JSAPI 触发面板
  4475. */ unmount () {
  4476. dispose();
  4477. iframeEl.parentNode?.removeChild(iframeEl);
  4478. }
  4479. };
  4480. }
  4481. const resolveSignatureFnMap = {
  4482. agentConfig: resolveAgentConfigParams,
  4483. suiteConfig: resolveSuiteConfigParams
  4484. };
  4485. async function resolveSignatureData(url, typeList) {
  4486. let lastError = new Error('Missing signature handler');
  4487. for (const type of typeList){
  4488. try {
  4489. if (!has$1(resolveSignatureFnMap, type)) {
  4490. continue;
  4491. }
  4492. return {
  4493. type,
  4494. params: await resolveSignatureFnMap[type](url)
  4495. };
  4496. } catch (error) {
  4497. lastError = error;
  4498. }
  4499. }
  4500. throw lastError;
  4501. }
  4502. function has(object, key) {
  4503. return Object.prototype.hasOwnProperty.call(object, key);
  4504. }
  4505. function isObject(val) {
  4506. return typeof val === 'object' && val !== null;
  4507. }
  4508. function includes(list, value) {
  4509. if (!list) {
  4510. return false;
  4511. }
  4512. return list.indexOf(value) >= 0;
  4513. }
  4514. var createIdentifier = createBuilder("Identifier" /* Types.Identifier */ , 'name');
  4515. var createLiteral = createBuilder("Literal" /* Types.Literal */ , 'value');
  4516. function createBuilder(type, key) {
  4517. return function(val) {
  4518. var _a;
  4519. return _a = {
  4520. type: type
  4521. }, _a[key] = val, _a;
  4522. };
  4523. }
  4524. function isIdentifierStart(ch) {
  4525. return isInRange(ch, 65, 90) // A-Z
  4526. || isInRange(ch, 97, 122) // a-z
  4527. || ch === 36 /* Code.dollarSign */ || ch === 95 /* Code.underscore */ ;
  4528. }
  4529. function isIdentifierPart(ch) {
  4530. return isIdentifierStart(ch) || isDecimalDigit(ch);
  4531. }
  4532. function isDecimalDigit(ch) {
  4533. return isInRange(ch, 48, 57); // 0-9
  4534. }
  4535. function isHexDigit(ch) {
  4536. return isDecimalDigit(ch) || isInRange(ch, 65, 70) // A-F
  4537. || isInRange(ch, 97, 102); // a-f
  4538. }
  4539. function isInRange(val, min, max) {
  4540. return val >= min && val <= max;
  4541. }
  4542. /**
  4543. * 12.6 Names and Keywords & 13.1 Identifiers
  4544. */ var LITERAL_NAME = {
  4545. "null": null,
  4546. "true": true,
  4547. "false": false,
  4548. NaN: NaN,
  4549. Infinity: Infinity
  4550. };
  4551. var reserveWords = ('await break case catch class const continue ' + 'debugger default delete do else enum export ' + 'extends false finally for function if import ' + 'in instanceof new null return super switch ' + 'this throw true try typeof var void while ' + 'with yield').split(' ');
  4552. var reserveWordMap = {};
  4553. for(var _i = 0, reserveWords_1 = reserveWords; _i < reserveWords_1.length; _i++){
  4554. var word = reserveWords_1[_i];
  4555. reserveWordMap[word] = true;
  4556. }
  4557. /**
  4558. * IdentifierReference
  4559. *
  4560. * https://tc39.es/ecma262/#prod-IdentifierReference
  4561. */ function parseIdentifierReference(ctx) {
  4562. var name = parseIdentifierName(ctx);
  4563. if (has(LITERAL_NAME, name)) {
  4564. return ctx.build(createLiteral(LITERAL_NAME[name]));
  4565. }
  4566. if (has(reserveWordMap, name)) {
  4567. ctx.unexpected(name);
  4568. }
  4569. return ctx.build(createIdentifier(name));
  4570. }
  4571. /**
  4572. * Identifier
  4573. *
  4574. * https://tc39.es/ecma262/#prod-Identifier
  4575. */ function parseIdentifier(ctx) {
  4576. var name = parseIdentifierName(ctx);
  4577. return ctx.build(createIdentifier(name));
  4578. }
  4579. /**
  4580. * IdentifierName
  4581. *
  4582. * https://tc39.es/ecma262/#prod-IdentifierName
  4583. */ function parseIdentifierName(ctx) {
  4584. if (!isIdentifierStart(ctx.peek())) {
  4585. ctx.unexpected();
  4586. }
  4587. var start = ctx.index;
  4588. do {
  4589. ctx.next();
  4590. }while (isIdentifierPart(ctx.peek()))
  4591. return ctx.expr.slice(start, ctx.index);
  4592. }
  4593. /**
  4594. * 12.8.3 Numeric Literals
  4595. */ /**
  4596. * NumericLiteral
  4597. *
  4598. * https://tc39.es/ecma262/#prod-NumericLiteral
  4599. */ function parseNumericLiteral(ctx) {
  4600. var number = '';
  4601. while(isDecimalDigit(ctx.peek())){
  4602. number += ctx.nextCh();
  4603. }
  4604. if (number === '0') {
  4605. // HexIntegerLiteral
  4606. // https://tc39.es/ecma262/#prod-HexIntegerLiteral
  4607. if (ctx.eat(120 /* Code.lowercaseX */ ) || ctx.eat(88 /* Code.uppercaseX */ )) {
  4608. number = '';
  4609. while(isHexDigit(ctx.peek())){
  4610. number += ctx.nextCh();
  4611. }
  4612. if (!number) {
  4613. ctx.unexpected();
  4614. }
  4615. return ctx.build(createLiteral(parseInt(number, 16)));
  4616. }
  4617. // BinaryIntegerLiteral
  4618. // https://tc39.es/ecma262/#prod-BinaryIntegerLiteral
  4619. if (ctx.eat(98 /* Code.lowercaseB */ ) || ctx.eat(66 /* Code.uppercaseB */ )) {
  4620. number = '';
  4621. while(ctx.peek() === 48 /* Code.digit0 */ || ctx.peek() === 49 /* Code.digit1 */ ){
  4622. number += ctx.nextCh();
  4623. }
  4624. if (!number) {
  4625. ctx.unexpected();
  4626. }
  4627. return ctx.build(createLiteral(parseInt(number, 2)));
  4628. }
  4629. }
  4630. if (ctx.peek() === 46 /* Code.dot */ ) {
  4631. number += ctx.nextCh();
  4632. while(isDecimalDigit(ctx.peek())){
  4633. number += ctx.nextCh();
  4634. }
  4635. }
  4636. // ExponentPart
  4637. // https://tc39.es/ecma262/#prod-ExponentPart
  4638. if (ctx.peek() === 101 /* Code.lowercaseE */ || ctx.peek() === 69 /* Code.uppercaseE */ ) {
  4639. number += ctx.nextCh();
  4640. if (ctx.peek() === 43 /* Code.plusSign */ || ctx.peek() === 45 /* Code.dash */ ) {
  4641. number += ctx.nextCh();
  4642. }
  4643. var hasDecimal = false;
  4644. while(isDecimalDigit(ctx.peek())){
  4645. hasDecimal = true;
  4646. number += ctx.nextCh();
  4647. }
  4648. if (!hasDecimal) {
  4649. ctx.unexpected();
  4650. }
  4651. }
  4652. if (isIdentifierStart(ctx.peek())) {
  4653. ctx["throw"]("Variable name cannot start with a number (".concat(number).concat(ctx.peekCh(), ")."));
  4654. }
  4655. if (ctx.peek() === 46 /* Code.dot */ || number === '.') {
  4656. ctx.unexpected();
  4657. }
  4658. return ctx.build(createLiteral(parseFloat(number)));
  4659. }
  4660. /**
  4661. * 12.8.4 String Literals
  4662. */ var ESCAPE_CHARACTER = {
  4663. n: '\n',
  4664. r: '\r',
  4665. t: '\t'
  4666. };
  4667. /**
  4668. * StringLiteral
  4669. *
  4670. * https://tc39.es/ecma262/#prod-StringLiteral
  4671. */ function parseStringLiteral(ctx) {
  4672. var quote = ctx.nextCh();
  4673. var value = '';
  4674. var ch;
  4675. while(ch = ctx.nextCh()){
  4676. if (ch === quote) {
  4677. return ctx.build(createLiteral(value));
  4678. }
  4679. if (ch !== '\\') {
  4680. value += ch;
  4681. continue;
  4682. }
  4683. ch = ctx.nextCh();
  4684. if (has(ESCAPE_CHARACTER, ch)) {
  4685. value += ESCAPE_CHARACTER[ch];
  4686. } else {
  4687. value += ch;
  4688. }
  4689. }
  4690. ctx.unexpected();
  4691. }
  4692. /**
  4693. * 13.2 Primary Expression
  4694. */ /**
  4695. * PrimaryExpression
  4696. *
  4697. * https://tc39.es/ecma262/#prod-PrimaryExpression
  4698. */ function parsePrimaryExpression(ctx) {
  4699. var code = ctx.peek();
  4700. if (isDecimalDigit(code) || code === 46 /* Code.dot */ ) {
  4701. return parseNumericLiteral(ctx);
  4702. }
  4703. if (code === 39 /* Code.singleQuote */ || code === 34 /* Code.doubleQuote */ ) {
  4704. return parseStringLiteral(ctx);
  4705. }
  4706. if (isIdentifierStart(code)) {
  4707. return parseIdentifierReference(ctx);
  4708. }
  4709. ctx.unexpected();
  4710. }
  4711. /**
  4712. * 13.3 Left-Hand-Side Expressions
  4713. */ /**
  4714. * LeftHandSideExpression
  4715. *
  4716. * https://tc39.es/ecma262/#prod-LeftHandSideExpression
  4717. */ function parseLeftHandSideExpression(ctx) {
  4718. var content = parsePrimaryExpression(ctx);
  4719. var code;
  4720. while(code = ctx.peek()){
  4721. // base [ prop ]
  4722. if (code === 91 /* Code.leftSquareBracket */ ) {
  4723. content = buildMemberExpression(ctx, content, true);
  4724. continue;
  4725. }
  4726. // base . prop
  4727. if (ctx.eat(46 /* Code.dot */ )) {
  4728. content = buildMemberExpression(ctx, content);
  4729. continue;
  4730. }
  4731. break;
  4732. }
  4733. return content;
  4734. }
  4735. /**
  4736. * MemberExpression
  4737. *
  4738. * https://tc39.es/ecma262/#prod-MemberExpression
  4739. */ function buildMemberExpression(ctx, object, computed) {
  4740. if (computed === void 0) {
  4741. computed = false;
  4742. }
  4743. var property;
  4744. if (computed) {
  4745. ctx.expect(91 /* Code.leftSquareBracket */ );
  4746. property = parseExpression(ctx);
  4747. ctx.expect(93 /* Code.rightSquareBracket */ );
  4748. } else {
  4749. property = parseIdentifier(ctx);
  4750. }
  4751. return ctx.build({
  4752. type: "MemberExpression" /* Types.MemberExpression */ ,
  4753. object: object,
  4754. property: property,
  4755. computed: computed
  4756. });
  4757. }
  4758. /**
  4759. * 13.16 Comma Operator ( , )
  4760. */ /**
  4761. * Expression
  4762. *
  4763. * https://tc39.es/ecma262/#prod-Expression
  4764. */ function parseExpression(ctx) {
  4765. return parseLeftHandSideExpression(ctx);
  4766. }
  4767. function createParserContext(expr) {
  4768. return {
  4769. expr: expr,
  4770. index: 0,
  4771. peek: function() {
  4772. return this.expr.charCodeAt(this.index);
  4773. },
  4774. peekCh: function() {
  4775. return this.expr.charAt(this.index);
  4776. },
  4777. next: function() {
  4778. this.index += 1;
  4779. },
  4780. nextCh: function() {
  4781. this.index += 1;
  4782. return this.expr.charAt(this.index - 1);
  4783. },
  4784. eat: function(ch) {
  4785. if (this.peek() !== ch) {
  4786. return false;
  4787. }
  4788. this.next();
  4789. this.skipWhitespace();
  4790. return true;
  4791. },
  4792. expect: function(ch) {
  4793. if (!this.eat(ch)) {
  4794. this.unexpected();
  4795. }
  4796. },
  4797. skip: function(length) {
  4798. this.index += length;
  4799. this.skipWhitespace();
  4800. },
  4801. skipWhitespace: function() {
  4802. var ch = expr.charCodeAt(this.index);
  4803. while(ch === 32 /* Code.space */ || ch === 9 /* Code.tab */ || ch === 13 /* Code.carriageReturn */ || ch === 10 /* Code.lineFeed */ ){
  4804. this.index += 1;
  4805. ch = expr.charCodeAt(this.index);
  4806. }
  4807. return this.index;
  4808. },
  4809. build: function(expr) {
  4810. this.skipWhitespace();
  4811. return expr;
  4812. },
  4813. unexpected: function(token) {
  4814. if (!token && this.index >= expr.length) {
  4815. throw this["throw"]('Unexpected end of input.');
  4816. }
  4817. throw this["throw"]("Unexpected token '".concat(token || this.peekCh(), "'."));
  4818. },
  4819. "throw": function(msg) {
  4820. throw new SyntaxError("".concat(msg, " (1:").concat(this.index, ")"));
  4821. }
  4822. };
  4823. }
  4824. function parseDataPath(input) {
  4825. var ctx = createParserContext(input.trim());
  4826. var ast = parseExpression(ctx);
  4827. if (ctx.index !== ctx.expr.length) {
  4828. ctx.unexpected();
  4829. }
  4830. return ast;
  4831. }
  4832. var DEFAULT_PROTECTED_KEYS = [
  4833. 'constrcutor',
  4834. 'prototype',
  4835. '__proto__'
  4836. ];
  4837. function patch(data, update, options) {
  4838. if (options === void 0) {
  4839. options = {};
  4840. }
  4841. var protectedKeys = options.protectedKeys || DEFAULT_PROTECTED_KEYS;
  4842. var set = options.set || defaultSet;
  4843. for(var _i = 0, _a = Object.keys(update); _i < _a.length; _i++){
  4844. var key = _a[_i];
  4845. if (includes(protectedKeys, key)) {
  4846. continue;
  4847. }
  4848. if (!includes(key, '[') && !includes(key, '.')) {
  4849. set(data, key, update[key]);
  4850. continue;
  4851. }
  4852. try {
  4853. var path = extractPath(parseDataPath(key), protectedKeys || []);
  4854. if (path) {
  4855. setIn(data, path, update[key], set);
  4856. } else {
  4857. set(data, key, update[key]);
  4858. }
  4859. } catch (error) {
  4860. set(data, key, update[key]);
  4861. }
  4862. }
  4863. }
  4864. function extractPath(expr, protectedKeys, path) {
  4865. if (protectedKeys === void 0) {
  4866. protectedKeys = [];
  4867. }
  4868. if (path === void 0) {
  4869. path = [];
  4870. }
  4871. if (expr.type === "Identifier" /* Types.Identifier */ ) {
  4872. path.unshift(expr.name);
  4873. return path;
  4874. }
  4875. if (expr.type !== "MemberExpression" /* Types.MemberExpression */ ) {
  4876. return;
  4877. }
  4878. var object = expr.object, property = expr.property, computed = expr.computed;
  4879. if (computed) {
  4880. if (property.type !== "Literal" /* Types.Literal */ ) {
  4881. return;
  4882. }
  4883. var value = property.value;
  4884. if (includes(protectedKeys, value)) {
  4885. return;
  4886. }
  4887. path.unshift(value);
  4888. } else {
  4889. if (property.type !== "Identifier" /* Types.Identifier */ ) {
  4890. return;
  4891. }
  4892. var name_1 = property.name;
  4893. if (includes(protectedKeys, name_1)) {
  4894. return;
  4895. }
  4896. path.unshift(name_1);
  4897. }
  4898. return extractPath(object, protectedKeys, path);
  4899. }
  4900. function setIn(data, path, value, set) {
  4901. var ptr = data;
  4902. for(var i = 0, ii = path.length - 1; i < ii; i++){
  4903. var key = path[i];
  4904. if (!has(ptr, key) || !isObject(ptr[key])) {
  4905. set(ptr, key, typeof path[i + 1] === 'string' ? {} : []);
  4906. }
  4907. ptr = ptr[key];
  4908. }
  4909. set(ptr, path[path.length - 1], value);
  4910. return ptr;
  4911. }
  4912. function defaultSet(object, key, value) {
  4913. // eslint-disable-next-line no-param-reassign
  4914. object[key] = value;
  4915. }
  4916. function cloneDeep(value) {
  4917. if (Array.isArray(value)) {
  4918. return value.map(cloneDeep);
  4919. }
  4920. if (value == null || typeof value !== 'object') {
  4921. return value;
  4922. }
  4923. const result = {};
  4924. for (const key of Object.keys(value)){
  4925. result[key] = cloneDeep(value[key]);
  4926. }
  4927. return result;
  4928. }
  4929. const contextMap = new WeakMap();
  4930. function setPluginContext(instance, internal) {
  4931. contextMap.set(instance, internal);
  4932. }
  4933. function getPluginContext(instance) {
  4934. return contextMap.get(instance);
  4935. }
  4936. function createOpenSessionInjector(params) {
  4937. return new Promise((resolve, reject)=>{
  4938. win.WWOpenData.createOpenSessionInjector(params, (error, injectOpenSession)=>{
  4939. if (error || !injectOpenSession) {
  4940. reject(error || new Error('System error'));
  4941. } else {
  4942. resolve(injectOpenSession);
  4943. }
  4944. });
  4945. });
  4946. }
  4947. function getHookNames(options) {
  4948. return Object.keys(options).filter((name)=>typeof options[name] === 'function');
  4949. }
  4950. function removeHooks(options) {
  4951. return Object.entries(options).reduce((acc, [name, value])=>{
  4952. if (typeof value !== 'function') {
  4953. acc[name] = value;
  4954. }
  4955. return acc;
  4956. }, {});
  4957. }
  4958. const FRAME_ORIGIN = 'https://open.work.weixin.qq.com';
  4959. const BUSINESS_URL = `${FRAME_ORIGIN}/wwopen/ww-open-data-frame`;
  4960. const PROTECTED_DATA_KEYS = [
  4961. 'constructor',
  4962. 'prototype',
  4963. '__proto__',
  4964. '__ob__'
  4965. ];
  4966. /**
  4967. * 创建 open-data frame 工厂对象。
  4968. *
  4969. * @compat WeCom >= 4.0.20
  4970. *
  4971. * @example
  4972. * ```ts
  4973. * const factory = ww.createOpenDataFrameFactory()
  4974. * const instance = factory.createOpenDataFrame(options)
  4975. *
  4976. * containerEl.appendChild(instance.el)
  4977. * ```
  4978. */ function createOpenDataFrameFactory(params) {
  4979. const initOpenDataPromise = isWeCom ? initOpenData() : undefined;
  4980. let openSessionInjectorPromise = createSessionInjector();
  4981. async function createSessionInjector() {
  4982. if (!isWeCom) {
  4983. return;
  4984. }
  4985. try {
  4986. await initOpenDataPromise;
  4987. return createOpenSessionInjector({
  4988. url: BUSINESS_URL
  4989. });
  4990. } catch (error) {
  4991. safeRun(params?.onError, error);
  4992. safeRun(params?.handleError, error);
  4993. throw error;
  4994. }
  4995. }
  4996. async function injectOpenSession(iframe) {
  4997. if (!isWeCom) {
  4998. return;
  4999. }
  5000. const injectSession = await openSessionInjectorPromise;
  5001. if (injectSession) {
  5002. injectSession(iframe);
  5003. }
  5004. }
  5005. function createOpenDataFrame(options) {
  5006. if (!options.template) {
  5007. throw new Error('options.template is required');
  5008. }
  5009. const iframeEl = createTransparentIFrame(options.el);
  5010. const registerOpenFramePromise = initOpenDataPromise?.then(()=>win?.WWOpenData?.registerOpenFrame(iframeEl));
  5011. const { subscribe, handleMessage } = createMsgDispatcher();
  5012. const { invoke: invoke$1, dispose } = useIframeClient(iframeEl, FRAME_ORIGIN, handleMessage);
  5013. const publicInstance = {
  5014. el: iframeEl,
  5015. data: cloneDeep(options.data) || {},
  5016. setData,
  5017. dispose: disposeComponent,
  5018. ...options.methods
  5019. };
  5020. async function setData(partialData) {
  5021. patch(publicInstance.data, partialData, {
  5022. protectedKeys: PROTECTED_DATA_KEYS
  5023. });
  5024. await invoke$1({
  5025. type: 'update',
  5026. options: {
  5027. data: partialData
  5028. }
  5029. });
  5030. }
  5031. function disposeComponent() {
  5032. dispose();
  5033. registerOpenFramePromise?.then((iframeId)=>{
  5034. win?.WWOpenData?.unregisterOpenFrame(iframeId);
  5035. });
  5036. }
  5037. setPluginContext(publicInstance, {
  5038. frame: publicInstance,
  5039. invoke: invoke$1,
  5040. subscribe
  5041. });
  5042. iframeEl.src = BUSINESS_URL;
  5043. subscribe('init', async ()=>{
  5044. return {
  5045. id: isWeCom ? await registerOpenFramePromise : undefined,
  5046. hooks: getHookNames(options),
  5047. options: removeHooks({
  5048. ...options,
  5049. el: undefined,
  5050. methods: undefined,
  5051. data: publicInstance.data
  5052. }),
  5053. config: {
  5054. support: [
  5055. 'injectSession'
  5056. ]
  5057. }
  5058. };
  5059. });
  5060. subscribe('call', (msg)=>{
  5061. let base = options;
  5062. if (msg.kind === 'method') {
  5063. base = base.methods;
  5064. }
  5065. return handleCallMsg(msg, base, publicInstance);
  5066. });
  5067. subscribe('injectSession', async ()=>{
  5068. await injectOpenSession(iframeEl);
  5069. });
  5070. subscribe('refreshSession', async ()=>{
  5071. openSessionInjectorPromise = createSessionInjector();
  5072. await injectOpenSession(iframeEl);
  5073. });
  5074. subscribe('invokeJsapi', (msg)=>{
  5075. return invoke('wwapp.invokeJsApiByCallInfo', {
  5076. callInfo: msg.callInfo
  5077. });
  5078. });
  5079. subscribe('invokeDownload', (msg)=>{
  5080. if (!msg.url.startsWith('https://open.work.weixin.qq.com/')) {
  5081. throw new Error('Invalid download url');
  5082. }
  5083. const el = document.createElement('a');
  5084. el.href = msg.url;
  5085. el.target = '_blank';
  5086. el.style.display = 'none';
  5087. el.click();
  5088. });
  5089. subscribe('agentConfig', async ()=>{
  5090. const url = getSignURL();
  5091. return {
  5092. url,
  5093. params: await resolveAgentConfigParams(url)
  5094. };
  5095. });
  5096. subscribe('modal', async (msg)=>{
  5097. const defaultPreviewType = isWeCom ? 'wecom-window' : undefined;
  5098. if (typeof options.handleModal !== 'function') {
  5099. return {
  5100. modalType: defaultPreviewType
  5101. };
  5102. }
  5103. const res = options.handleModal({
  5104. modalUrl: msg.modalUrl,
  5105. modalSize: msg.modalSize
  5106. });
  5107. return {
  5108. modalType: res === false ? 'iframe' : defaultPreviewType
  5109. };
  5110. });
  5111. return publicInstance;
  5112. }
  5113. return {
  5114. /**
  5115. * 创建 open-data frame 组件
  5116. */ createOpenDataFrame
  5117. };
  5118. }
  5119. /**
  5120. * 显示确认安全网关配置页面。
  5121. *
  5122. * 在桌面端页面以 iframe 弹窗的形式覆盖在页面上;在移动端页面将跳转至确认页面,返回后页面需要主动确认 confirm_id 的确认情况。
  5123. */ function showSecurityGatewayConfirmModal(options) {
  5124. const url = new URL('https://open.work.weixin.qq.com/wwopen/secureGateway/confirm');
  5125. url.searchParams.set('confirm_id', options.confirmId);
  5126. if (isIOS || isAndroid) {
  5127. location.href = url.href;
  5128. return;
  5129. }
  5130. url.searchParams.set('modal', 'true');
  5131. const client = showModalFrame(url.href, (msg)=>{
  5132. switch(msg.type){
  5133. case 'call':
  5134. return handleCallMsg(msg, options);
  5135. case 'close':
  5136. return;
  5137. default:
  5138. throw new Error(`Unknown message type '${msg.type}'`);
  5139. }
  5140. });
  5141. return {
  5142. /**
  5143. * 弹窗面板的 iframe 元素
  5144. */ el: client.el,
  5145. /**
  5146. * 卸载弹窗面板
  5147. */ unmount () {
  5148. client.dispose();
  5149. client.el.parentNode?.removeChild(client.el);
  5150. }
  5151. };
  5152. }
  5153. const SDK_VERSION = "2.3.1";
  5154. exports.WWLoginType = void 0;
  5155. (function(WWLoginType) {
  5156. /**
  5157. * [第三方应用登录](#45846)
  5158. */ WWLoginType["serviceApp"] = "ServiceApp";
  5159. /**
  5160. * [企业自建应用登录](/document/path/98151)、[服务商代开发应用登录](/document/path/98173)
  5161. */ WWLoginType["corpApp"] = "CorpApp";
  5162. })(exports.WWLoginType || (exports.WWLoginType = {}));
  5163. exports.WWLoginLangType = void 0;
  5164. (function(WWLoginLangType) {
  5165. /**
  5166. * 中文
  5167. */ WWLoginLangType["zh"] = "zh";
  5168. /**
  5169. * 英文
  5170. */ WWLoginLangType["en"] = "en";
  5171. })(exports.WWLoginLangType || (exports.WWLoginLangType = {}));
  5172. exports.WWLoginRedirectType = void 0;
  5173. (function(WWLoginRedirectType) {
  5174. /**
  5175. * 默认 `top window` 顶层页面跳转
  5176. */ WWLoginRedirectType["top"] = "top";
  5177. /**
  5178. * 通过 `onLoginSuccess` 回调用户授权 `code`,开发者自行处理跳转
  5179. */ WWLoginRedirectType["callback"] = "callback";
  5180. /**
  5181. * 登录组件跳转
  5182. */ WWLoginRedirectType["self"] = "self";
  5183. })(exports.WWLoginRedirectType || (exports.WWLoginRedirectType = {}));
  5184. exports.WWLoginPanelSizeType = void 0;
  5185. (function(WWLoginPanelSizeType) {
  5186. /**
  5187. * 默认: 480x416px
  5188. */ WWLoginPanelSizeType["middle"] = "middle";
  5189. /**
  5190. * 小尺寸: 320x380px
  5191. */ WWLoginPanelSizeType["small"] = "small";
  5192. })(exports.WWLoginPanelSizeType || (exports.WWLoginPanelSizeType = {}));
  5193. const PANEL_SIZE = {
  5194. [exports.WWLoginPanelSizeType.middle]: [
  5195. '480px',
  5196. '416px'
  5197. ],
  5198. [exports.WWLoginPanelSizeType.small]: [
  5199. '320px',
  5200. '380px'
  5201. ]
  5202. };
  5203. /**
  5204. * 初始化企业微信Web登录组件,创建登录面板。
  5205. *
  5206. * @example
  5207. * ```ts
  5208. * // 初始化登录组件
  5209. * const wwLogin = ww.createWWLoginPanel({
  5210. * el: '#ww_login',
  5211. * params: {
  5212. * login_type: 'CorpApp',
  5213. * appid: 'wwbbb6a7b539f2xxxxx',
  5214. * agentid: '10000xx',
  5215. * redirect_uri: 'https://work.weixin.qq.com',
  5216. * state: 'loginState',
  5217. * redirect_type: 'callback',
  5218. * },
  5219. * onCheckWeComLogin({ isWeComLogin }) {
  5220. * console.log(isWeComLogin)
  5221. * },
  5222. * onLoginSuccess({ code }) {
  5223. * console.log({ code })
  5224. * },
  5225. * onLoginFail(err) {
  5226. * console.log(err)
  5227. * },
  5228. * })
  5229. * ```
  5230. */ function createWWLoginPanel(options) {
  5231. const { width, height } = getPanelSize(options.params?.panel_size);
  5232. const iframeEl = createTransparentIFrame(options.el);
  5233. const { style } = iframeEl;
  5234. style.width = width;
  5235. style.height = height;
  5236. const { dispose } = useIframeClient(iframeEl, 'https://login.work.weixin.qq.com', (msg)=>{
  5237. if (msg.type === 'call') {
  5238. return handleCallMsg(msg, options);
  5239. }
  5240. throw new Error(`Unknown message type '${msg.type}'`);
  5241. });
  5242. const url = new URL('https://login.work.weixin.qq.com/wwlogin/sso/login');
  5243. for (const key of Object.keys(options.params || {})){
  5244. url.searchParams.set(key, options.params[key]);
  5245. }
  5246. url.searchParams.set('version', SDK_VERSION);
  5247. iframeEl.src = url.href;
  5248. return {
  5249. el: iframeEl,
  5250. unmount () {
  5251. dispose();
  5252. iframeEl.parentNode?.removeChild(iframeEl);
  5253. }
  5254. };
  5255. }
  5256. function getPanelSize(panelSizeType = exports.WWLoginPanelSizeType.middle) {
  5257. const size = PANEL_SIZE[panelSizeType] || PANEL_SIZE[exports.WWLoginPanelSizeType.middle];
  5258. return {
  5259. width: size[0],
  5260. height: size[1]
  5261. };
  5262. }
  5263. function createSingleton(factory) {
  5264. const map = new WeakMap();
  5265. return (object, ...args)=>{
  5266. if (!map.has(object)) {
  5267. map.set(object, factory(object, ...args));
  5268. }
  5269. return map.get(object);
  5270. };
  5271. }
  5272. function createWeakRef(target) {
  5273. if (typeof WeakRef !== 'undefined') {
  5274. return new WeakRef(target);
  5275. }
  5276. return {
  5277. deref: ()=>target
  5278. };
  5279. }
  5280. function createPlugin(factory) {
  5281. return createSingleton((instance)=>{
  5282. const context = getPluginContext(instance);
  5283. if (!context) {
  5284. throw new TypeError('Illegal invocation');
  5285. }
  5286. return factory(context);
  5287. });
  5288. }
  5289. const useRefManager = createPlugin(({ frame, invoke, subscribe })=>{
  5290. const refid2refMap = new Map();
  5291. const refid2eventMap = new Map();
  5292. subscribe('ref.event', (msg)=>{
  5293. const subscribers = refid2eventMap.get(msg.refId);
  5294. if (!subscribers) {
  5295. return;
  5296. }
  5297. for (const fn of subscribers){
  5298. fn(msg.data);
  5299. }
  5300. });
  5301. subscribe('refDispose', (msg)=>{
  5302. refid2refMap.delete(msg.refId);
  5303. refid2eventMap.delete(msg.refId);
  5304. });
  5305. async function getRef(name) {
  5306. const res = await invoke({
  5307. type: 'ref.get',
  5308. name
  5309. });
  5310. if (!res) {
  5311. return;
  5312. }
  5313. const ref = refid2refMap.get(res.refId)?.deref();
  5314. if (ref) {
  5315. return ref;
  5316. }
  5317. const newRef = createRef(res.refId);
  5318. refid2refMap.set(res.refId, createWeakRef(newRef));
  5319. return newRef;
  5320. }
  5321. function createRef(refId) {
  5322. if (!refid2eventMap.has(refId)) {
  5323. refid2eventMap.set(refId, []);
  5324. }
  5325. const subscribers = refid2eventMap.get(refId);
  5326. function invokeRef(name, data, opts) {
  5327. return invoke({
  5328. type: 'ref.call',
  5329. refId,
  5330. name,
  5331. data
  5332. }, opts);
  5333. }
  5334. function subscribeRef(fn) {
  5335. subscribers.push(fn);
  5336. return ()=>{
  5337. const index = subscribers.indexOf(fn);
  5338. if (index >= 0) {
  5339. subscribers.splice(index, 1);
  5340. }
  5341. };
  5342. }
  5343. return {
  5344. frame,
  5345. invoke: invokeRef,
  5346. subscribe: subscribeRef
  5347. };
  5348. }
  5349. return {
  5350. get: getRef
  5351. };
  5352. });
  5353. function createSymbolKey(name) {
  5354. if (typeof Symbol === 'function') {
  5355. return Symbol(name);
  5356. }
  5357. return name;
  5358. }
  5359. /// <reference types="../../../types/arraybuffer.d.ts" />
  5360. const MIN_PAGE_SIZE = 64 * 1024;
  5361. const MAX_PAGE_SIZE = 1024 * 1024;
  5362. class BufferList {
  5363. concat() {
  5364. if (this.list.length === 1) {
  5365. return stabilizeBufferItem(this.current);
  5366. }
  5367. const result = new Uint8Array(this.list.reduce((total, item)=>total + item.offset, 0));
  5368. this.list.reduce((offset, item)=>{
  5369. result.set(new Uint8Array(stabilizeBufferItem(item)), offset);
  5370. return offset + item.offset;
  5371. }, 0);
  5372. return result.buffer;
  5373. }
  5374. ensureCapacity(size) {
  5375. const current = this.current;
  5376. const minNewSize = current.offset + size;
  5377. if (minNewSize <= current.size) {
  5378. return;
  5379. }
  5380. const buffer = current.buffer;
  5381. if (!buffer.resizable || minNewSize > buffer.maxByteLength) {
  5382. this.current = this.createBufferItem();
  5383. this.list.push(this.current);
  5384. } else {
  5385. current.size = Math.min(current.size * 2, buffer.maxByteLength);
  5386. buffer.resize(current.size);
  5387. }
  5388. }
  5389. createBufferItem() {
  5390. const buffer = new ArrayBuffer(MIN_PAGE_SIZE, {
  5391. maxByteLength: MAX_PAGE_SIZE
  5392. });
  5393. return {
  5394. view: new DataView(buffer),
  5395. buffer,
  5396. size: buffer.byteLength,
  5397. offset: 0
  5398. };
  5399. }
  5400. constructor(){
  5401. _define_property(this, "list", void 0);
  5402. _define_property(this, "current", void 0);
  5403. this.current = this.createBufferItem();
  5404. this.list = [
  5405. this.current
  5406. ];
  5407. }
  5408. }
  5409. function stabilizeBufferItem(item) {
  5410. if (item.offset >= item.size) {
  5411. return item.buffer;
  5412. }
  5413. if (item.buffer.resizable && item.buffer.transfer) {
  5414. return item.buffer.transfer(item.offset);
  5415. }
  5416. return item.buffer.slice(0, item.offset);
  5417. }
  5418. var VariantType;
  5419. (function(VariantType) {
  5420. VariantType[VariantType["int32"] = 1] = "int32";
  5421. VariantType[VariantType["float64"] = 2] = "float64";
  5422. VariantType[VariantType["boolean"] = 3] = "boolean";
  5423. VariantType[VariantType["null"] = 4] = "null";
  5424. VariantType[VariantType["undefined"] = 5] = "undefined";
  5425. VariantType[VariantType["valueRef"] = 6] = "valueRef";
  5426. })(VariantType || (VariantType = {}));
  5427. const MIN_INT32 = -Math.pow(2, 31);
  5428. const MAX_INT32 = Math.pow(2, 31);
  5429. function create() {
  5430. return {
  5431. buffer: new BufferList(),
  5432. values: [],
  5433. stringIndexMap: new Map()
  5434. };
  5435. }
  5436. function encode(state) {
  5437. return {
  5438. buffer: state.buffer.concat(),
  5439. values: state.values
  5440. };
  5441. }
  5442. function uint8(state, value) {
  5443. state.buffer.ensureCapacity(1);
  5444. const current = state.buffer.current;
  5445. current.view.setUint8(current.offset, value);
  5446. current.offset += 1;
  5447. }
  5448. function int32(state, value) {
  5449. state.buffer.ensureCapacity(4);
  5450. const current = state.buffer.current;
  5451. current.view.setInt32(current.offset, value);
  5452. current.offset += 4;
  5453. }
  5454. function uint32(state, value) {
  5455. state.buffer.ensureCapacity(4);
  5456. const current = state.buffer.current;
  5457. current.view.setUint32(current.offset, value);
  5458. current.offset += 4;
  5459. }
  5460. function float64(state, value) {
  5461. state.buffer.ensureCapacity(8);
  5462. const current = state.buffer.current;
  5463. current.view.setFloat64(current.offset, value);
  5464. current.offset += 8;
  5465. }
  5466. function string(state, value) {
  5467. let index = state.stringIndexMap.get(value);
  5468. if (!index) {
  5469. index = state.values.push(value);
  5470. state.stringIndexMap.set(value, index);
  5471. }
  5472. uint32(state, index - 1);
  5473. }
  5474. function unknown(state, value) {
  5475. uint32(state, state.values.push(value) - 1);
  5476. }
  5477. function variant(state, value) {
  5478. if (value === null) {
  5479. uint8(state, 4);
  5480. return;
  5481. }
  5482. switch(typeof value){
  5483. case 'number':
  5484. if (isInt32(value)) {
  5485. uint8(state, 1);
  5486. int32(state, value);
  5487. break;
  5488. }
  5489. uint8(state, 2);
  5490. float64(state, value);
  5491. break;
  5492. case 'string':
  5493. uint8(state, 6);
  5494. string(state, value);
  5495. break;
  5496. case 'boolean':
  5497. uint8(state, 3);
  5498. uint8(state, value ? 1 : 0);
  5499. break;
  5500. case 'undefined':
  5501. uint8(state, 5);
  5502. break;
  5503. default:
  5504. uint8(state, 6);
  5505. unknown(state, value);
  5506. break;
  5507. }
  5508. }
  5509. function isInt32(value) {
  5510. if (!Number.isInteger(value)) {
  5511. return false;
  5512. }
  5513. return MIN_INT32 <= value && value < MAX_INT32;
  5514. }
  5515. var CommandType;
  5516. (function(CommandType) {
  5517. CommandType[CommandType["set"] = 1] = "set";
  5518. CommandType[CommandType["call"] = 2] = "call";
  5519. CommandType[CommandType["dispose"] = 3] = "dispose";
  5520. })(CommandType || (CommandType = {}));
  5521. var ValueType;
  5522. (function(ValueType) {
  5523. ValueType[ValueType["value"] = 1] = "value";
  5524. ValueType[ValueType["ref"] = 2] = "ref";
  5525. })(ValueType || (ValueType = {}));
  5526. const KEY_REFLECT_ID = createSymbolKey('__WECOM_REFLECT_ID__');
  5527. const useReflectStore = createPlugin(({ invoke })=>{
  5528. const finalizationRegistry = typeof FinalizationRegistry === 'function' ? new FinalizationRegistry(cleanup) : null;
  5529. // WHY: weakSet.has(obj) + obj[key] 速度远快于 weakMap.get(obj)
  5530. const reflectObjectSet = new WeakSet();
  5531. let nextReflectId = 1;
  5532. const flushPromise = Promise.resolve();
  5533. let flushPending = false;
  5534. let writer = create();
  5535. function bind(obj, reflectId = genReflectId()) {
  5536. if (reflectObjectSet.has(obj)) {
  5537. return obj[KEY_REFLECT_ID];
  5538. }
  5539. obj[KEY_REFLECT_ID] = reflectId;
  5540. reflectObjectSet.add(obj);
  5541. finalizationRegistry?.register(obj, reflectId);
  5542. return reflectId;
  5543. }
  5544. function set(obj, name, value) {
  5545. const refId = obj[KEY_REFLECT_ID];
  5546. if (!refId) {
  5547. throw new TypeError('Illegal invocation');
  5548. }
  5549. uint8(writer, 1);
  5550. uint32(writer, refId);
  5551. string(writer, name);
  5552. writeCustomValue(value);
  5553. enqueueFlush();
  5554. }
  5555. function call(obj, name, args, result) {
  5556. const refId = obj[KEY_REFLECT_ID];
  5557. if (!refId) {
  5558. throw new TypeError('Illegal invocation');
  5559. }
  5560. uint8(writer, 2);
  5561. uint32(writer, refId);
  5562. string(writer, name);
  5563. uint32(writer, (result ? result[KEY_REFLECT_ID] : 0) ?? 0);
  5564. uint32(writer, args.length);
  5565. args.forEach(writeCustomValue);
  5566. enqueueFlush();
  5567. }
  5568. function cleanup(refId) {
  5569. uint8(writer, 3);
  5570. uint32(writer, refId);
  5571. enqueueFlush();
  5572. }
  5573. function writeCustomValue(value) {
  5574. if (reflectObjectSet.has(value)) {
  5575. uint8(writer, 2);
  5576. uint32(writer, value[KEY_REFLECT_ID]);
  5577. } else {
  5578. uint8(writer, 1);
  5579. variant(writer, value);
  5580. }
  5581. }
  5582. function enqueueFlush() {
  5583. if (flushPending) {
  5584. return;
  5585. }
  5586. flushPending = true;
  5587. flushPromise.then(flush);
  5588. }
  5589. function flush() {
  5590. flushPending = false;
  5591. const commands = encode(writer);
  5592. writer = create();
  5593. invoke({
  5594. type: 'reflect.command',
  5595. commands
  5596. }, {
  5597. serialize: false,
  5598. dropResult: true,
  5599. transfer: [
  5600. commands.buffer
  5601. ]
  5602. });
  5603. }
  5604. function genReflectId() {
  5605. return nextReflectId++;
  5606. }
  5607. return {
  5608. genReflectId,
  5609. bind,
  5610. set,
  5611. call
  5612. };
  5613. });
  5614. function _class_apply_descriptor_get(receiver, descriptor) {
  5615. if (descriptor.get) return descriptor.get.call(receiver);
  5616. return descriptor.value;
  5617. }
  5618. function _class_extract_field_descriptor(receiver, privateMap, action) {
  5619. if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
  5620. return privateMap.get(receiver);
  5621. }
  5622. function _class_private_field_get(receiver, privateMap) {
  5623. var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
  5624. return _class_apply_descriptor_get(receiver, descriptor);
  5625. }
  5626. function _check_private_redeclaration(obj, privateCollection) {
  5627. if (privateCollection.has(obj)) {
  5628. throw new TypeError("Cannot initialize the same private elements twice on an object");
  5629. }
  5630. }
  5631. function _class_private_field_init(obj, privateMap, value) {
  5632. _check_private_redeclaration(obj, privateMap);
  5633. privateMap.set(obj, value);
  5634. }
  5635. function _class_apply_descriptor_set(receiver, descriptor, value) {
  5636. if (descriptor.set) descriptor.set.call(receiver, value);
  5637. else {
  5638. if (!descriptor.writable) {
  5639. // This should only throw in strict mode, but class bodies are
  5640. // always strict and private fields can only be used inside
  5641. // class bodies.
  5642. throw new TypeError("attempted to set read only private field");
  5643. }
  5644. descriptor.value = value;
  5645. }
  5646. }
  5647. function _class_private_field_set(receiver, privateMap, value) {
  5648. var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
  5649. _class_apply_descriptor_set(receiver, descriptor, value);
  5650. return value;
  5651. }
  5652. const wrapper2NativeMap = new WeakMap();
  5653. const native2wrapperMap = new WeakMap();
  5654. function setNativeObject(wrapped, native) {
  5655. wrapper2NativeMap.set(wrapped, native);
  5656. native2wrapperMap.set(native, wrapped);
  5657. }
  5658. function toNativeValue(wrapped) {
  5659. if (wrapper2NativeMap.has(wrapped)) {
  5660. return wrapper2NativeMap.get(wrapped);
  5661. }
  5662. return wrapped;
  5663. }
  5664. function toWrappedValue(native) {
  5665. if (native2wrapperMap.has(native)) {
  5666. return native2wrapperMap.get(native);
  5667. }
  5668. return native;
  5669. }
  5670. const PLACEHOLDER_SRC = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
  5671. let placeholderImage = null;
  5672. function getPlaceholderImage() {
  5673. if (!placeholderImage) {
  5674. placeholderImage = new Image();
  5675. placeholderImage.src = PLACEHOLDER_SRC;
  5676. }
  5677. return placeholderImage;
  5678. }
  5679. var _src = /*#__PURE__*/ new WeakMap(), _complete = /*#__PURE__*/ new WeakMap(), _error = /*#__PURE__*/ new WeakMap();
  5680. let _KEY_REFLECT_ID$3 = KEY_REFLECT_ID;
  5681. class ImageResource {
  5682. get src() {
  5683. return _class_private_field_get(this, _src);
  5684. }
  5685. get loading() {
  5686. return !_class_private_field_get(this, _complete);
  5687. }
  5688. get complete() {
  5689. return _class_private_field_get(this, _complete);
  5690. }
  5691. get error() {
  5692. return _class_private_field_get(this, _error);
  5693. }
  5694. __handleSettled(error) {
  5695. _class_private_field_set(this, _complete, true);
  5696. _class_private_field_set(this, _error, error);
  5697. if (error) {
  5698. safeRun(this.onerror, error);
  5699. } else {
  5700. safeRun(this.onload, undefined);
  5701. }
  5702. }
  5703. constructor(src){
  5704. _define_property(this, _KEY_REFLECT_ID$3, void 0);
  5705. _define_property(this, "onload", void 0);
  5706. _define_property(this, "onerror", void 0);
  5707. _class_private_field_init(this, _src, {
  5708. writable: true,
  5709. value: void 0
  5710. });
  5711. _class_private_field_init(this, _complete, {
  5712. writable: true,
  5713. value: false
  5714. });
  5715. _class_private_field_init(this, _error, {
  5716. writable: true,
  5717. value: void 0
  5718. });
  5719. _class_private_field_set(this, _src, src);
  5720. setNativeObject(this, getPlaceholderImage());
  5721. }
  5722. }
  5723. const useImageStore = createPlugin(({ frame, invoke, subscribe })=>{
  5724. const reflectStore = useReflectStore(frame);
  5725. const imageSettledHandlerMap = new Map();
  5726. function createImage(data, type) {
  5727. const res = new ImageResource(data);
  5728. const refId = reflectStore.bind(res);
  5729. invoke({
  5730. type: 'image.load',
  5731. refId,
  5732. data: getImageInfo(data, type)
  5733. }, {
  5734. serialize: typeof data === 'string'
  5735. });
  5736. imageSettledHandlerMap.set(refId, (msg)=>{
  5737. res.__handleSettled(msg.error);
  5738. });
  5739. return res;
  5740. }
  5741. function getImageInfo(data, mime) {
  5742. if (typeof data === 'string') {
  5743. return {
  5744. type: 'url',
  5745. src: data
  5746. };
  5747. }
  5748. return {
  5749. type: 'arraybuffer',
  5750. data,
  5751. mime
  5752. };
  5753. }
  5754. subscribe('image.settled', (msg)=>{
  5755. const handler = imageSettledHandlerMap.get(msg.refId);
  5756. imageSettledHandlerMap.delete(msg.refId);
  5757. if (handler) {
  5758. handler(msg);
  5759. }
  5760. });
  5761. return {
  5762. createImage
  5763. };
  5764. });
  5765. const useRefEventManager = createSingleton((ref)=>{
  5766. const listenerMap = new Map();
  5767. ref.subscribe((msg)=>{
  5768. if (msg.type !== 'event.trigger') {
  5769. return;
  5770. }
  5771. const listeners = listenerMap.get(`${msg.capture}|${msg.name}`);
  5772. if (!listeners?.size) {
  5773. return;
  5774. }
  5775. const event = createCustomEvent(msg.event);
  5776. for (const listener of Array.from(listeners)){
  5777. safeRun(listener, event);
  5778. }
  5779. });
  5780. function addListener(name, listener, options) {
  5781. const capture = typeof options === 'boolean' ? options : !!options?.capture;
  5782. if (!listenerMap.has(`${capture}|${name}`)) {
  5783. listenerMap.set(`${capture}|${name}`, new Set());
  5784. }
  5785. const listeners = listenerMap.get(`${capture}|${name}`);
  5786. if (!listeners.size) {
  5787. ref.invoke('event.subscribe', {
  5788. name,
  5789. capture
  5790. });
  5791. }
  5792. listeners.add(listener);
  5793. }
  5794. function removeListener(name, listener, options) {
  5795. const capture = typeof options === 'boolean' ? options : !!options?.capture;
  5796. if (!listenerMap.has(`${capture}|${name}`)) {
  5797. return;
  5798. }
  5799. const listeners = listenerMap.get(`${capture}|${name}`);
  5800. listeners.delete(listener);
  5801. if (!listeners.size) {
  5802. ref.invoke('event.unsubscribe', {
  5803. name,
  5804. capture
  5805. });
  5806. }
  5807. }
  5808. return {
  5809. addListener,
  5810. removeListener
  5811. };
  5812. });
  5813. function createCustomEvent(info) {
  5814. const event = new CustomEvent(info.type, {
  5815. detail: info.detail
  5816. });
  5817. for (const key of Object.keys(info)){
  5818. if (!(key in event)) {
  5819. event[key] = info[key];
  5820. }
  5821. }
  5822. Object.defineProperties(event, {
  5823. target: {
  5824. value: info.target
  5825. },
  5826. currentTarget: {
  5827. value: info.currentTarget
  5828. }
  5829. });
  5830. return event;
  5831. }
  5832. var _store$1 = /*#__PURE__*/ new WeakMap(), _native$1 = /*#__PURE__*/ new WeakMap();
  5833. let _KEY_REFLECT_ID$2 = KEY_REFLECT_ID;
  5834. class FrameCanvasPattern {
  5835. setTransform(matrix) {
  5836. _class_private_field_get(this, _native$1).setTransform(matrix);
  5837. _class_private_field_get(this, _store$1).call(this, 'setTransform', [
  5838. matrix
  5839. ]);
  5840. }
  5841. constructor(store, native){
  5842. _define_property(this, _KEY_REFLECT_ID$2, void 0);
  5843. _class_private_field_init(this, _store$1, {
  5844. writable: true,
  5845. value: void 0
  5846. });
  5847. _class_private_field_init(this, _native$1, {
  5848. writable: true,
  5849. value: void 0
  5850. });
  5851. _class_private_field_set(this, _store$1, store);
  5852. _class_private_field_set(this, _native$1, native);
  5853. store.bind(this);
  5854. setNativeObject(this, native);
  5855. }
  5856. }
  5857. var _store1 = /*#__PURE__*/ new WeakMap(), _native1 = /*#__PURE__*/ new WeakMap();
  5858. let _KEY_REFLECT_ID1 = KEY_REFLECT_ID;
  5859. class FrameCanvasGradient {
  5860. addColorStop(offset, color) {
  5861. _class_private_field_get(this, _native1).addColorStop(offset, color);
  5862. _class_private_field_get(this, _store1).call(this, 'addColorStop', [
  5863. offset,
  5864. color
  5865. ]);
  5866. }
  5867. constructor(store, native){
  5868. _define_property(this, _KEY_REFLECT_ID1, void 0);
  5869. _class_private_field_init(this, _store1, {
  5870. writable: true,
  5871. value: void 0
  5872. });
  5873. _class_private_field_init(this, _native1, {
  5874. writable: true,
  5875. value: void 0
  5876. });
  5877. _class_private_field_set(this, _store1, store);
  5878. _class_private_field_set(this, _native1, native);
  5879. store.bind(this);
  5880. setNativeObject(this, native);
  5881. }
  5882. }
  5883. /**
  5884. * 纯样式属性
  5885. *
  5886. * 修改这些属性不会改变 CANVAS_LOCAL_METHODS 的表现,因此无需映射到 native object
  5887. */ const CANVAS_STYLE_PROPS = [
  5888. 'fillStyle',
  5889. 'filter',
  5890. 'globalAlpha',
  5891. 'globalCompositeOperation',
  5892. 'imageSmoothingEnabled',
  5893. 'imageSmoothingQuality',
  5894. 'shadowBlur',
  5895. 'shadowColor',
  5896. 'shadowOffsetX',
  5897. 'shadowOffsetY',
  5898. 'strokeStyle'
  5899. ];
  5900. const CANVAS_CONFIG_PROPS = [
  5901. 'direction',
  5902. 'font',
  5903. 'fontKerning',
  5904. 'fontStretch',
  5905. 'fontVariantCaps',
  5906. 'letterSpacing',
  5907. 'lineCap',
  5908. 'lineDashOffset',
  5909. 'lineJoin',
  5910. 'lineWidth',
  5911. 'miterLimit',
  5912. 'textAlign',
  5913. 'textBaseline',
  5914. 'textRendering',
  5915. 'wordSpacing'
  5916. ];
  5917. const CANVAS_CONFIG_METHODS = [
  5918. 'arc',
  5919. 'arcTo',
  5920. 'beginPath',
  5921. 'bezierCurveTo',
  5922. 'clip',
  5923. 'closePath',
  5924. 'ellipse',
  5925. 'lineTo',
  5926. 'moveTo',
  5927. 'quadraticCurveTo',
  5928. 'rect',
  5929. 'reset',
  5930. 'resetTransform',
  5931. 'restore',
  5932. 'rotate',
  5933. 'roundRect',
  5934. 'save',
  5935. 'scale',
  5936. 'setLineDash',
  5937. 'setTransform',
  5938. 'transform',
  5939. 'translate'
  5940. ];
  5941. const CANVAS_DRAW_METHODS = [
  5942. 'clearRect',
  5943. 'drawFocusIfNeeded',
  5944. 'drawImage',
  5945. 'fill',
  5946. 'fillRect',
  5947. 'fillText',
  5948. 'stroke',
  5949. 'strokeRect',
  5950. 'strokeText'
  5951. ];
  5952. const CANVAS_LOCAL_METHODS = [
  5953. 'getContextAttributes',
  5954. 'getLineDash',
  5955. 'getTransform',
  5956. 'isContextLost',
  5957. 'isPointInPath',
  5958. 'isPointInStroke',
  5959. 'measureText'
  5960. ];
  5961. const CANVAS_FACTORY_METHODS = [
  5962. [
  5963. 'createConicGradient',
  5964. FrameCanvasGradient
  5965. ],
  5966. [
  5967. 'createLinearGradient',
  5968. FrameCanvasGradient
  5969. ],
  5970. [
  5971. 'createPattern',
  5972. FrameCanvasPattern
  5973. ],
  5974. [
  5975. 'createRadialGradient',
  5976. FrameCanvasGradient
  5977. ]
  5978. ];
  5979. const KEY_INTERNAL = createSymbolKey('__WECOM_INTERNAL__');
  5980. const createFrameContext = createSingleton((canvas, store, native)=>new FrameCanvasRenderingContext2D(canvas, store, native));
  5981. let _KEY_INTERNAL = KEY_INTERNAL, _KEY_REFLECT_ID$1 = KEY_REFLECT_ID;
  5982. class FrameCanvasRenderingContext2D {
  5983. constructor(canvas, store, native){
  5984. _define_property(this, "canvas", void 0);
  5985. _define_property(this, _KEY_INTERNAL, void 0);
  5986. _define_property(this, _KEY_REFLECT_ID$1, void 0);
  5987. this.canvas = canvas;
  5988. this[KEY_INTERNAL] = {
  5989. store,
  5990. native,
  5991. props: Object.create(null)
  5992. };
  5993. store.bind(this);
  5994. setNativeObject(this, native);
  5995. }
  5996. }
  5997. const FrameContextProto = FrameCanvasRenderingContext2D.prototype;
  5998. for (const name of CANVAS_STYLE_PROPS){
  5999. Object.defineProperty(FrameContextProto, name, {
  6000. configurable: true,
  6001. enumerable: true,
  6002. get () {
  6003. const { native, props } = this[KEY_INTERNAL];
  6004. return props[name] ?? toWrappedValue(native[name]);
  6005. },
  6006. set (value) {
  6007. const { store, props } = this[KEY_INTERNAL];
  6008. props[name] = toNativeValue(value);
  6009. store.set(this, name, value);
  6010. }
  6011. });
  6012. }
  6013. for (const name of CANVAS_CONFIG_PROPS){
  6014. Object.defineProperty(FrameContextProto, name, {
  6015. configurable: true,
  6016. enumerable: true,
  6017. get () {
  6018. return toWrappedValue(this[KEY_INTERNAL].native[name]);
  6019. },
  6020. set (value) {
  6021. const { store, native } = this[KEY_INTERNAL];
  6022. native[name] = toNativeValue(value);
  6023. store.set(this, name, value);
  6024. }
  6025. });
  6026. }
  6027. for (const name of CANVAS_LOCAL_METHODS){
  6028. FrameContextProto[name] = function(...args) {
  6029. const { native } = this[KEY_INTERNAL];
  6030. return callNative(native, name, args);
  6031. };
  6032. }
  6033. for (const name of CANVAS_CONFIG_METHODS){
  6034. FrameContextProto[name] = function(...args) {
  6035. const { store, native } = this[KEY_INTERNAL];
  6036. callNative(native, name, args);
  6037. store.call(this, name, args);
  6038. };
  6039. }
  6040. for (const name of CANVAS_DRAW_METHODS){
  6041. FrameContextProto[name] = function(...args) {
  6042. const { store } = this[KEY_INTERNAL];
  6043. store.call(this, name, args);
  6044. };
  6045. }
  6046. for (const [name, Ctor] of CANVAS_FACTORY_METHODS){
  6047. FrameContextProto[name] = function(...args) {
  6048. const { store, native } = this[KEY_INTERNAL];
  6049. const nativeRes = callNative(native, name, args);
  6050. const frameRes = new Ctor(store, nativeRes);
  6051. store.call(this, name, args, frameRes);
  6052. return frameRes;
  6053. };
  6054. }
  6055. function callNative(native, name, args) {
  6056. switch(args.length){
  6057. case 1:
  6058. return native[name](args[0]);
  6059. case 2:
  6060. return native[name](args[0], args[1]);
  6061. case 3:
  6062. return native[name](args[0], args[1], args[2]);
  6063. case 4:
  6064. return native[name](args[0], args[1], args[2], args[3]);
  6065. case 5:
  6066. return native[name](args[0], args[1], args[2], args[3], args[4]);
  6067. case 6:
  6068. return native[name](args[0], args[1], args[2], args[3], args[4], args[5]);
  6069. default:
  6070. return native[name](...args);
  6071. }
  6072. }
  6073. var _native = /*#__PURE__*/ new WeakMap(), _store = /*#__PURE__*/ new WeakMap(), _imageStore = /*#__PURE__*/ new WeakMap(), _refEvent = /*#__PURE__*/ new WeakMap(), _context = /*#__PURE__*/ new WeakMap();
  6074. let _KEY_REFLECT_ID = KEY_REFLECT_ID;
  6075. class FrameCanvas {
  6076. /**
  6077. * canvas 元素宽度
  6078. */ get width() {
  6079. return _class_private_field_get(this, _native).width;
  6080. }
  6081. set width(value) {
  6082. _class_private_field_get(this, _native).width = value;
  6083. _class_private_field_get(this, _store).set(this, 'width', value);
  6084. }
  6085. /**
  6086. * canvas 元素高度
  6087. */ get height() {
  6088. return _class_private_field_get(this, _native).height;
  6089. }
  6090. set height(value) {
  6091. _class_private_field_get(this, _native).height = value;
  6092. _class_private_field_get(this, _store).set(this, 'height', value);
  6093. }
  6094. createImage(data, type) {
  6095. return _class_private_field_get(this, _imageStore).createImage(data, type);
  6096. }
  6097. /**
  6098. * 获取 canvas 的上下文
  6099. *
  6100. * @param type 上下文类型,目前只支持 2d
  6101. * @param attrs 渲染上下文配置
  6102. */ getContext(type, attrs) {
  6103. if (type !== '2d') {
  6104. throw new Error(`Failed to execute 'getContext' on 'FrameCanvas': The provided value '${type}' is not a valid enum value of type RenderingContextType`);
  6105. }
  6106. if (_class_private_field_get(this, _context)) {
  6107. return _class_private_field_get(this, _context);
  6108. }
  6109. const nativeContext = _class_private_field_get(this, _native).getContext(type, attrs);
  6110. _class_private_field_set(this, _context, createFrameContext(this, _class_private_field_get(this, _store), nativeContext));
  6111. _class_private_field_get(this, _store).call(this, 'getContext', [
  6112. type,
  6113. attrs
  6114. ], _class_private_field_get(this, _context));
  6115. return _class_private_field_get(this, _context);
  6116. }
  6117. addEventListener(type, listener, options) {
  6118. _class_private_field_get(this, _refEvent).addListener(type, listener, options);
  6119. }
  6120. removeEventListener(type, listener, options) {
  6121. _class_private_field_get(this, _refEvent).removeListener(type, listener, options);
  6122. }
  6123. constructor(ref, refId, info){
  6124. /** @internal */ _define_property(this, _KEY_REFLECT_ID, void 0);
  6125. _class_private_field_init(this, _native, {
  6126. writable: true,
  6127. value: void 0
  6128. });
  6129. _class_private_field_init(this, _store, {
  6130. writable: true,
  6131. value: void 0
  6132. });
  6133. _class_private_field_init(this, _imageStore, {
  6134. writable: true,
  6135. value: void 0
  6136. });
  6137. _class_private_field_init(this, _refEvent, {
  6138. writable: true,
  6139. value: void 0
  6140. });
  6141. _class_private_field_init(this, _context, {
  6142. writable: true,
  6143. value: void 0
  6144. });
  6145. _class_private_field_set(this, _native, new OffscreenCanvas(info.width, info.height));
  6146. _class_private_field_set(this, _store, useReflectStore(ref.frame));
  6147. _class_private_field_get(this, _store).bind(this, refId);
  6148. _class_private_field_set(this, _imageStore, useImageStore(ref.frame));
  6149. _class_private_field_set(this, _refEvent, useRefEventManager(ref));
  6150. setNativeObject(this, _class_private_field_get(this, _native));
  6151. }
  6152. }
  6153. const ref2canvasMap = new WeakMap();
  6154. const getCanvasId = createSingleton((ref)=>{
  6155. const { genReflectId } = useReflectStore(ref.frame);
  6156. return genReflectId();
  6157. });
  6158. /**
  6159. * 获取 open-data frame 组件内的 canvas 元素。
  6160. *
  6161. * @param instance open-data frame 组件实例
  6162. * @param refName 模板引用名称
  6163. *
  6164. * @example
  6165. * ```ts
  6166. * const canvas = await ww.getCanvas(frame, 'canvas')
  6167. * const context = canvas.getContext('2d')
  6168. * ```
  6169. */ async function getCanvas(instance, refName) {
  6170. const { get: getRef } = useRefManager(instance);
  6171. const ref = await getRef(refName);
  6172. if (!ref) {
  6173. return;
  6174. }
  6175. if (ref2canvasMap.has(ref)) {
  6176. return ref2canvasMap.get(ref);
  6177. }
  6178. const refId = getCanvasId(ref);
  6179. const info = await ref.invoke('bind', {
  6180. refId
  6181. });
  6182. if (!info) {
  6183. return;
  6184. }
  6185. if (!ref2canvasMap.has(ref)) {
  6186. ref2canvasMap.set(ref, new FrameCanvas(ref, refId, info));
  6187. }
  6188. return ref2canvasMap.get(ref);
  6189. }
  6190. const getScrollViewContext = createSingleton((ref)=>{
  6191. return {
  6192. scrollTo (options) {
  6193. ref.invoke('scrollTo', options);
  6194. },
  6195. scrollIntoView (selector, options) {
  6196. ref.invoke('scrollIntoView', {
  6197. selector,
  6198. options
  6199. });
  6200. }
  6201. };
  6202. });
  6203. /**
  6204. * 创建 open-data frame 组件内指定 scroll-view 元素的上下文。
  6205. *
  6206. * @param instance open-data frame 组件实例
  6207. * @param refName 模板引用名称
  6208. *
  6209. * @example
  6210. * ```ts
  6211. * const scrollView = await ww.createScrollViewContext(instance, 'scroll-view')
  6212. *
  6213. * scrollView.scrollTo({ top: 100 })
  6214. * ```
  6215. */ async function createScrollViewContext(instance, refName) {
  6216. const { get: getRef } = useRefManager(instance);
  6217. const ref = await getRef(refName);
  6218. if (!ref) {
  6219. return;
  6220. }
  6221. return getScrollViewContext(ref);
  6222. }
  6223. /**
  6224. * 获取节点的相关信息
  6225. *
  6226. * @param instance open-data frame 组件实例
  6227. * @param refName 模板引用名称
  6228. * @param fields 需要获取的字段
  6229. *
  6230. * @example
  6231. * ```ts
  6232. * ww.getNodeInfo(instance, 'node-ref')
  6233. * ```
  6234. */ async function getNodeInfo(instance, refName, fields) {
  6235. const { get: getRef } = useRefManager(instance);
  6236. const ref = await getRef(refName);
  6237. if (!ref) {
  6238. return;
  6239. }
  6240. return ref.invoke('nodeInfo.get', {
  6241. fields
  6242. });
  6243. }
  6244. /**
  6245. * From https://gist.github.com/schacon/12703
  6246. */ function hex_sha1(s) {
  6247. return rstr2hex(rstr_sha1(s));
  6248. }
  6249. /**
  6250. * Calculate the SHA1 of a raw string
  6251. */ function rstr_sha1(s) {
  6252. return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));
  6253. }
  6254. /**
  6255. * Convert a raw string to a hex string
  6256. */ function rstr2hex(input) {
  6257. const hex_tab = '0123456789abcdef';
  6258. let output = '';
  6259. let x;
  6260. for(let i = 0; i < input.length; i++){
  6261. x = input.charCodeAt(i);
  6262. output += hex_tab.charAt(x >>> 4 & 0x0f) + hex_tab.charAt(x & 0x0f);
  6263. }
  6264. return output;
  6265. }
  6266. /**
  6267. * Convert a raw string to an array of big-endian words
  6268. * Characters >255 have their high-byte silently ignored.
  6269. */ function rstr2binb(input) {
  6270. const output = new Array(input.length >> 2);
  6271. for(let i = 0; i < output.length; i++)output[i] = 0;
  6272. for(let i = 0; i < input.length * 8; i += 8)output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << 24 - i % 32;
  6273. return output;
  6274. }
  6275. /**
  6276. * Convert an array of little-endian words to a string
  6277. */ function binb2rstr(input) {
  6278. let output = '';
  6279. for(let i = 0; i < input.length * 32; i += 8)output += String.fromCharCode(input[i >> 5] >>> 24 - i % 32 & 0xff);
  6280. return output;
  6281. }
  6282. /**
  6283. * Calculate the SHA-1 of an array of big-endian words, and a bit length
  6284. */ function binb_sha1(x, len) {
  6285. /* append padding */ x[len >> 5] |= 0x80 << 24 - len % 32;
  6286. x[(len + 64 >> 9 << 4) + 15] = len;
  6287. const w = new Array(80);
  6288. let a = 1732584193;
  6289. let b = -271733879;
  6290. let c = -1732584194;
  6291. let d = 271733878;
  6292. let e = -1009589776;
  6293. for(let i = 0; i < x.length; i += 16){
  6294. const olda = a;
  6295. const oldb = b;
  6296. const oldc = c;
  6297. const oldd = d;
  6298. const olde = e;
  6299. for(let j = 0; j < 80; j++){
  6300. if (j < 16) w[j] = x[i + j];
  6301. else w[j] = bit_rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
  6302. const t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)), safe_add(safe_add(e, w[j]), sha1_kt(j)));
  6303. e = d;
  6304. d = c;
  6305. c = bit_rol(b, 30);
  6306. b = a;
  6307. a = t;
  6308. }
  6309. a = safe_add(a, olda);
  6310. b = safe_add(b, oldb);
  6311. c = safe_add(c, oldc);
  6312. d = safe_add(d, oldd);
  6313. e = safe_add(e, olde);
  6314. }
  6315. return [
  6316. a,
  6317. b,
  6318. c,
  6319. d,
  6320. e
  6321. ];
  6322. }
  6323. /**
  6324. * Perform the appropriate triplet combination function for the current
  6325. * iteration
  6326. */ function sha1_ft(t, b, c, d) {
  6327. if (t < 20) return b & c | ~b & d;
  6328. if (t < 40) return b ^ c ^ d;
  6329. if (t < 60) return b & c | b & d | c & d;
  6330. return b ^ c ^ d;
  6331. }
  6332. /**
  6333. * Determine the appropriate additive constant for the current iteration
  6334. */ function sha1_kt(t) {
  6335. return t < 20 ? 1518500249 : t < 40 ? 1859775393 : t < 60 ? -1894007588 : -899497514;
  6336. }
  6337. /**
  6338. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  6339. * to work around bugs in some JS interpreters.
  6340. */ function safe_add(x, y) {
  6341. const lsw = (x & 0xffff) + (y & 0xffff);
  6342. const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  6343. return msw << 16 | lsw & 0xffff;
  6344. }
  6345. /**
  6346. * Bitwise rotate a 32-bit number to the left.
  6347. */ function bit_rol(num, cnt) {
  6348. return num << cnt | num >>> 32 - cnt;
  6349. }
  6350. function getSignature(options) {
  6351. let normalized = options;
  6352. if (typeof options === 'string') {
  6353. normalized = {
  6354. ticket: options
  6355. };
  6356. }
  6357. const nonceStr = normalized.nonceStr || random();
  6358. const timestamp = normalized.timestamp || Math.floor(Date.now() / 1000);
  6359. const url = normalized.url || getHref().split('#')[0];
  6360. const ticket = normalized.ticket;
  6361. const signature = hex_sha1(`jsapi_ticket=${ticket}&noncestr=${nonceStr}&timestamp=${timestamp}&url=${url}`);
  6362. return {
  6363. timestamp,
  6364. nonceStr,
  6365. signature
  6366. };
  6367. }
  6368. const env = {
  6369. isWeChat,
  6370. isWeCom
  6371. };
  6372. const IS_WECOM_SDK = true;
  6373. exports.FrameCanvas = FrameCanvas;
  6374. exports.IS_WECOM_SDK = IS_WECOM_SDK;
  6375. exports.SDK_VERSION = SDK_VERSION;
  6376. exports.addCard = addCard;
  6377. exports.addDevice = addDevice;
  6378. exports.checkJsApi = checkJsApi;
  6379. exports.checkSchedule = checkSchedule;
  6380. exports.chooseCard = chooseCard;
  6381. exports.chooseImage = chooseImage;
  6382. exports.chooseInvoice = chooseInvoice;
  6383. exports.chooseMessageFile = chooseMessageFile;
  6384. exports.chooseWXPay = chooseWXPay;
  6385. exports.claimClassAdmin = claimClassAdmin;
  6386. exports.closeBLEConnection = closeBLEConnection;
  6387. exports.closeBluetoothAdapter = closeBluetoothAdapter;
  6388. exports.closeWindow = closeWindow;
  6389. exports.connectWifi = connectWifi;
  6390. exports.consumeAndShareCard = consumeAndShareCard;
  6391. exports.createBLEConnection = createBLEConnection;
  6392. exports.createChatWithMsg = createChatWithMsg;
  6393. exports.createCorpGroupChat = createCorpGroupChat;
  6394. exports.createDoc = createDoc;
  6395. exports.createExternalPayment = createExternalPayment;
  6396. exports.createJSAPIPanel = createJSAPIPanel;
  6397. exports.createOpenDataFrameFactory = createOpenDataFrameFactory;
  6398. exports.createSchoolPayment = createSchoolPayment;
  6399. exports.createScrollViewContext = createScrollViewContext;
  6400. exports.createWWLoginPanel = createWWLoginPanel;
  6401. exports.discoverDevice = discoverDevice;
  6402. exports.downloadImage = downloadImage;
  6403. exports.downloadLivingReplay = downloadLivingReplay;
  6404. exports.downloadVoice = downloadVoice;
  6405. exports.ensureAgentConfigReady = ensureAgentConfigReady;
  6406. exports.ensureConfigReady = ensureConfigReady;
  6407. exports.ensureCorpConfigReady = ensureCorpConfigReady;
  6408. exports.enterHWOpenTalk = enterHWOpenTalk;
  6409. exports.enterpriseVerify = enterpriseVerify;
  6410. exports.env = env;
  6411. exports.getApprovalSelectedItems = getApprovalSelectedItems;
  6412. exports.getBLEDeviceCharacteristics = getBLEDeviceCharacteristics;
  6413. exports.getBLEDeviceServices = getBLEDeviceServices;
  6414. exports.getBeacons = getBeacons;
  6415. exports.getBluetoothAdapterState = getBluetoothAdapterState;
  6416. exports.getBluetoothDevices = getBluetoothDevices;
  6417. exports.getCanvas = getCanvas;
  6418. exports.getClipboardData = getClipboardData;
  6419. exports.getConnectedBluetoothDevices = getConnectedBluetoothDevices;
  6420. exports.getConnectedWifi = getConnectedWifi;
  6421. exports.getContext = getContext;
  6422. exports.getCurCorpGroupChat = getCurCorpGroupChat;
  6423. exports.getCurCorpGroupContact = getCurCorpGroupContact;
  6424. exports.getCurExternalChat = getCurExternalChat;
  6425. exports.getCurExternalContact = getCurExternalContact;
  6426. exports.getLocalFileData = getLocalFileData;
  6427. exports.getLocalImgData = getLocalImgData;
  6428. exports.getLocation = getLocation;
  6429. exports.getNetworkType = getNetworkType;
  6430. exports.getNodeInfo = getNodeInfo;
  6431. exports.getShareInfo = getShareInfo;
  6432. exports.getSignature = getSignature;
  6433. exports.getVerifyParams = getVerifyParams;
  6434. exports.getWifiList = getWifiList;
  6435. exports.hideAllNonBaseMenuItem = hideAllNonBaseMenuItem;
  6436. exports.hideChatAttachmentMenu = hideChatAttachmentMenu;
  6437. exports.hideMenuItems = hideMenuItems;
  6438. exports.hideOptionMenu = hideOptionMenu;
  6439. exports.initOpenData = initOpenData;
  6440. exports.invoke = invoke;
  6441. exports.launchMiniprogram = launchMiniprogram;
  6442. exports.navigateToAddCustomer = navigateToAddCustomer;
  6443. exports.navigateToKfChat = navigateToKfChat;
  6444. exports.notifyBLECharacteristicValueChange = notifyBLECharacteristicValueChange;
  6445. exports.on = on;
  6446. exports.onBLECharacteristicValueChange = onBLECharacteristicValueChange;
  6447. exports.onBLEConnectionStateChange = onBLEConnectionStateChange;
  6448. exports.onBeaconServiceChange = onBeaconServiceChange;
  6449. exports.onBeaconUpdate = onBeaconUpdate;
  6450. exports.onBluetoothAdapterStateChange = onBluetoothAdapterStateChange;
  6451. exports.onBluetoothDeviceFound = onBluetoothDeviceFound;
  6452. exports.onGetWifiList = onGetWifiList;
  6453. exports.onHistoryBack = onHistoryBack;
  6454. exports.onLocationChange = onLocationChange;
  6455. exports.onMenuShareAppMessage = onMenuShareAppMessage;
  6456. exports.onMenuShareQQ = onMenuShareQQ;
  6457. exports.onMenuShareQZone = onMenuShareQZone;
  6458. exports.onMenuShareTimeline = onMenuShareTimeline;
  6459. exports.onMenuShareWechat = onMenuShareWechat;
  6460. exports.onMenuShareWeibo = onMenuShareWeibo;
  6461. exports.onNetworkStatusChange = onNetworkStatusChange;
  6462. exports.onSearchBeacons = onSearchBeacons;
  6463. exports.onUserCaptureScreen = onUserCaptureScreen;
  6464. exports.onVoicePlayEnd = onVoicePlayEnd;
  6465. exports.onVoiceRecordEnd = onVoiceRecordEnd;
  6466. exports.onWifiConnected = onWifiConnected;
  6467. exports.openAddress = openAddress;
  6468. exports.openAppComment = openAppComment;
  6469. exports.openAppDeviceDataAuth = openAppDeviceDataAuth;
  6470. exports.openAppManage = openAppManage;
  6471. exports.openAppPurchase = openAppPurchase;
  6472. exports.openBluetoothAdapter = openBluetoothAdapter;
  6473. exports.openBusinessView = openBusinessView;
  6474. exports.openCard = openCard;
  6475. exports.openDefaultBrowser = openDefaultBrowser;
  6476. exports.openDeviceProfile = openDeviceProfile;
  6477. exports.openEnterpriseChat = openEnterpriseChat;
  6478. exports.openEnterpriseRedPacket = openEnterpriseRedPacket;
  6479. exports.openExistedChatWithMsg = openExistedChatWithMsg;
  6480. exports.openLocation = openLocation;
  6481. exports.openProductSpecificView = openProductSpecificView;
  6482. exports.openThirdAppServiceChat = openThirdAppServiceChat;
  6483. exports.openUserProfile = openUserProfile;
  6484. exports.pauseVoice = pauseVoice;
  6485. exports.playVoice = playVoice;
  6486. exports.previewFile = previewFile;
  6487. exports.previewImage = previewImage;
  6488. exports.printFile = printFile;
  6489. exports.queryCurrHWOpenTalk = queryCurrHWOpenTalk;
  6490. exports.readBLECharacteristicValue = readBLECharacteristicValue;
  6491. exports.refundExternalPayment = refundExternalPayment;
  6492. exports.register = register;
  6493. exports.replayLiving = replayLiving;
  6494. exports.saveApprovalSelectedItems = saveApprovalSelectedItems;
  6495. exports.scanQRCode = scanQRCode;
  6496. exports.selectCorpGroupContact = selectCorpGroupContact;
  6497. exports.selectEnterpriseContact = selectEnterpriseContact;
  6498. exports.selectExternalContact = selectExternalContact;
  6499. exports.selectPrivilegedContact = selectPrivilegedContact;
  6500. exports.sendChatMessage = sendChatMessage;
  6501. exports.setClipboardData = setClipboardData;
  6502. exports.setKeepScreenOn = setKeepScreenOn;
  6503. exports.setShareAttr = setShareAttr;
  6504. exports.shareAppMessage = shareAppMessage;
  6505. exports.shareToExternalChat = shareToExternalChat;
  6506. exports.shareToExternalContact = shareToExternalContact;
  6507. exports.shareToExternalMoments = shareToExternalMoments;
  6508. exports.shareWechatMessage = shareWechatMessage;
  6509. exports.showAllNonBaseMenuItem = showAllNonBaseMenuItem;
  6510. exports.showMenuItems = showMenuItems;
  6511. exports.showOptionMenu = showOptionMenu;
  6512. exports.showSecurityGatewayConfirmModal = showSecurityGatewayConfirmModal;
  6513. exports.startAutoLBS = startAutoLBS;
  6514. exports.startBeaconDiscovery = startBeaconDiscovery;
  6515. exports.startBluetoothDevicesDiscovery = startBluetoothDevicesDiscovery;
  6516. exports.startLiving = startLiving;
  6517. exports.startMeeting = startMeeting;
  6518. exports.startRecord = startRecord;
  6519. exports.startSearchBeacons = startSearchBeacons;
  6520. exports.startWecast = startWecast;
  6521. exports.startWifi = startWifi;
  6522. exports.stopAutoLBS = stopAutoLBS;
  6523. exports.stopBeaconDiscovery = stopBeaconDiscovery;
  6524. exports.stopBluetoothDevicesDiscovery = stopBluetoothDevicesDiscovery;
  6525. exports.stopRecord = stopRecord;
  6526. exports.stopSearchBeacons = stopSearchBeacons;
  6527. exports.stopVoice = stopVoice;
  6528. exports.stopWifi = stopWifi;
  6529. exports.thirdPartyOpenPage = thirdPartyOpenPage;
  6530. exports.translateVoice = translateVoice;
  6531. exports.updateAppMessageShareData = updateAppMessageShareData;
  6532. exports.updateCorpGroupChat = updateCorpGroupChat;
  6533. exports.updateEnterpriseChat = updateEnterpriseChat;
  6534. exports.updateMomentsSetting = updateMomentsSetting;
  6535. exports.updateTimelineShareData = updateTimelineShareData;
  6536. exports.uploadImage = uploadImage;
  6537. exports.uploadVoice = uploadVoice;
  6538. exports.wedocSelectDoc = wedocSelectDoc;
  6539. exports.wedriveSelectDir = wedriveSelectDir;
  6540. exports.wedriveSelectFile = wedriveSelectFile;
  6541. exports.wedriveSelectFileForDownload = wedriveSelectFileForDownload;
  6542. exports.wedriveSelectFileForShare = wedriveSelectFileForShare;
  6543. exports.writeBLECharacteristicValue = writeBLECharacteristicValue;